Skip to content

Modus-Logo-Long-BlackCreated with Sketch.

  • Services
  • Work
  • Blog
  • Resources

    OUR RESOURCES

    Innovation Podcast

    Explore transformative innovation with industry leaders.

    Guides & Playbooks

    Implement leading digital innovation with our strategic guides.

    Practical guide to building an effective AI strategy
  • Who we are

    Our story

    Learn about our values, vision, and commitment to client success.

    Open Source

    Discover how we contribute to and benefit from the global open source ecosystem.

    Careers

    Join our dynamic team and shape the future of digital transformation.

    How we built our unique culture
  • Let's talk
  • EN
  • FR

Mission Impossible:Hiding Image-Not-Found Icons

Published on October 30, 2015
Last Updated on April 7, 2021
Application Development

[Cue dramatic music]

Your mission, should you choose to accept it, is to build a list of contacts that shows a profile picture and a name. For contacts that don’t have a profile picture, you should display their initials instead. There is also one catch: if any of the profile images fail to load, you should show their initials.

For example:

image00 I know what you’re thinking: “<img> tags and onerror handlers.”

No.

I would normally agree but this is Mission Impossible so let’s try something different. Say we have a React component that renders our list like this:

Instead of having an <img> tag in this render method, we can break that out into its own <ObjectImage> component and add some logic to it.

The secret here is in using the <object> tag to load our images instead of an <img> tag. Set the data attribute to the image source ie “./images/myimage.jpg” and then set the type attribute to the appropriate content type.

The contents of the <object> tag will be rendered if the object data cannot be rendered, so, you are free to provide whatever alternate content you need there. In our case, we are extracting the contact’s initials from the name. Then, simply style as needed.

Voila!

View the CodePen here.

[This post will self-destruct in five seconds. Good luck.]

Posted in Application Development
Share this

Timothy Eagan

Timothy Eagan was a Senior Engineer at Modus Create, and is an accomplished software developer with over 20 years of experience in creating customized business solutions. He can be found in Providence, RI. Tim is also an OIF veteran, former paperboy and part-time comedian.
Follow

Related Posts

  • Writing Cucumber Features: Which Approach is Better?
    Writing Cucumber Features:
    Which Approach is Better?

    Cucumber is an awesome tool that can help your team create living documentation for your…

  • Protractor Parameters: Adding Flexibility To Automation Tests
    Add Flexibility to Automation Tests with Protractor

    If you’re willing to read the API docs on it and do a little experimenting,…

Want more insights to fuel your innovation efforts?

Sign up to receive our monthly newsletter and exclusive content about digital transformation and product development.

What we do

Our services
AI and data
Product development
Design and UX
IT modernization
Platform and MLOps
Developer experience
Security

Our partners
Atlassian
AWS
GitHub
Other partners

Who we are

Our story
Careers
Open source

Our work

Our case studies

Our resources

Blog
Innovation podcast
Guides & playbooks

Connect with us

Get monthly insights on AI adoption

© 2025 Modus Create, LLC

Privacy PolicySitemap
Scroll To Top
  • Services
  • Work
  • Blog
  • Resources
    • Innovation Podcast
    • Guides & Playbooks
  • Who we are
    • Our story
    • Careers
  • Let’s talk
  • EN
  • FR