惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
PCI Perspectives
PCI Perspectives
Webroot Blog
Webroot Blog
Help Net Security
Help Net Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
S
Securelist
V2EX - 技术
V2EX - 技术
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Cloudbric
Cloudbric
GbyAI
GbyAI
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
P
Proofpoint News Feed
SecWiki News
SecWiki News
T
Tailwind CSS Blog
腾讯CDC
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
M
MIT News - Artificial intelligence
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
T
Troy Hunt's Blog
G
Google Developers Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
D
DataBreaches.Net
V
Vulnerabilities – Threatpost
博客园 - 叶小钗
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Know Your Adversary
Know Your Adversary
T
Tor Project blog
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
Y
Y Combinator Blog
H
Help Net Security
Latest news
Latest news

ImageKit.io Blog

Next.js Image Optimization with ImageKit Use Video as a Background in Your Next.js Project How to Fix Autoplay Video in Next.js How Durian Scaled a Visual-First Retail Experience to 350K Monthly Visitors Online How Matsmart accelerated image delivery across countries with ImageKit AI in Digital Asset Management: From Smart Workflows to Agentic Automation How Joseph Joseph unified and secured global video delivery with ImageKit How Modall powers fast, effortless media delivery across 40+ projects with ImageKit Digital Asset Management (DAM) Trends: 2026 Report How to add a poster image to Video.js player (and automate it) HLS streaming with Video.js + React Building the future of storytelling with fast, AI-powered video delivery How PushOwl delivers 100M+ image-rich notifications seamlessly with ImageKit How Homify delivers millions of interior design images seamlessly with ImageKit Better event discovery with lightning‑fast videos & images Adding video player in React Native Video player in Angular applications Crop and resize videos in React Next.js image and video upload React image and video upload React video optimization How we quadrupled our traffic to 625K monthly page views How Apollo 24|7 boosted performance & reduced costs with ImageKit Simplify your media workflows with ImageKit DAM integrations Extending Lighthouse for custom image and video optimization analysis Brand Asset Management: What is it? How does it work? WordPress Digital Asset Management Guide - Manage your WP media assets better Why Shopify retailers need a digital asset management solution DAM vs. SharePoint: Which is best for you? AI-powered Metadata and Tagging in Digital Asset Management How Hopscotch built India's largest online Kids' fashion brand with ImageKit Dropbox Vs. DAM: Which Is The Right Tool For Digital Asset Management Digital Asset Management for Photographers: A Complete Guide Why digital asset management for agencies is essential Helping both Top and Bottom Line: SaffronStays rapid, profitable growth with ImageKit How KreditBee simplified media experiences with ImageKit Google Drive alternatives for businesses (with fast-growing teams) Node.js image upload ImageKit: The Secret Ingredient in Swiggy’s Expansion Journey Streamlining the Design Approval Process: A Comprehensive Guide AV1 Codec - Complete guide for video application devs PHP image and video upload Angular image & video upload AV1 vs VP9: Which codec should you choose? Adding video player in Next.js React Video Player VP8 vs VP9 - In the context of online video delivery Exploring WebM vs MP4 7 Free Digital Asset Management Software that are not Open-Source Comparing 9 Top Digital Asset Management Tools in the Market What are Brand Standards and Why do they Matter? Boost Sales and Brand Appeal: Essential Tips for eCommerce Image Management Brand Recall: The Strategy to Create Unforgettable Brands How to upload files in HTML? Branding for Small Businesses (2025 Edition) Everything you need to know about VP9 codec Recent updates from ImageKit and what's next Best Ways to Write RFP For Digital Asset Management (+ with free RFP template) What is Brand Dilution? How to Avoid It? Explained with [Examples] The Importance of Brand Identity: Leveraging Digital Asset Management for Impact From Launch to Scale: How to Launch a Brand Campaign Digital Asset Management Requirements - What do You Need to Evaluate and How? Marketing Collateral Management: A Quick End-to-End Guide Video Content Management System: What Is It And How To Choose One? Dropbox vs. Google Drive vs. Onedrive: The Best Cloud Storage Solution How to Build Brand Trust: Get Started In 2025 Google Drive vs. Box: A Detailed Comparison How Digital Asset Management Solutions Help Protect Brand Equity A DAM Solution Can Safeguard Your Digital Intellectual Property - Here’s How WebP Vs. PNG: Which Image Format Should You Use and Why? How to Resize Images in Bootstrap Easily Progressive jpegs (PJPEG): the key to loading images faster on your website Dropbox vs. Google Drive: The Best Cloud Storage For Digital Assets Dropbox Pros & Cons In 2024: An In-Depth Analysis and Why A DAM Solution Stands Out Google Drive Vs OneDrive: The Better Storage Option For Digital Assets Manage your video assets better with video metadata Understanding DAM's Role in Strengthening Brand Identity Digital asset management strategy: What to know before creating one The Ultimate Guide To Marketing Agency Onboarding 6 Solutions To Simplify Large File Sharing Over The Web A Step-by-Step Breakdown of a Video Production Workflow 13 Digital Asset Management Use Cases You Should Know How to Conduct a Brand Audit and Manage Your Brand Assets Costly Consequences of Inconsistent Branding And How DAM Can Help Dynamic Asset Transformation: What It Is, Why You Need It, and How ImageKit Can Help Everything You Need to Know About HTML Video Autoplay How To Select Your DAM Vendor: A Complete Guide How to Boost User Experience with Smart Digital Asset Management React Image Optimization: A Guide for Web Developers Why Should DAM Be A Part Of Your MarTech Stack? Unleashing the Power of Content Repurposing with ImageKit MKV vs MP4: Which Video File Format Is Better for Your Needs? Digital Asset Management For Ecommerce: A Complete Guide How an Image Tagging Software can Transform Your Image Search How to Manage Your Content Lifecycle Effectively M4V vs MP4: Which Video Format Should You Use and Why? Why Every Business Needs An Image Management System All The Questions To Ask During A Dam Demo Which is the Best Image Format for Your Website? Uploading Multiple Files Using JavaScript: A Comprehensive Guide
How To Handle Loading Of Images That May Not Exist?
Rahul Nanwani · 2017-05-30 · via ImageKit.io Blog

When you are handling millions of images on your website or mobile application, it's quite possible, over a period of time, a few images may cease to exist. And when you try to deliver those images on your applications, the users end up seeing a broken image like the one below.

A sample page with broken images as seen on Google Chrome browser
A sample page with broken images as seen on Google Chrome browser

Surely this is not something that you would want showing up on your application. But how to handle loading of images that don't exist anymore?

Let's talk about some ways you can fix this broken image problem to maintain the UX standards of your application.

1. Periodic data cleanup

If an image does not exist, then it should be removed from the database.

An image URL that is incorrect or points to an image that no longer exists, is most likely a data issue. So the first thing that you can do to counter the broken image problem is to periodically check all images for sanity.

You would pick up a list of image URLs that have been added over, let’s say, the last week and check if you are able to retrieve those images (a 200 OK HTTP response). If yes, then the image stays in your database, else you can discard the image.

Advantages

  • Solves the problem at the root level.
  • One-time effort in writing the script.

Disadvantages

  • Lengthy execution times (nearly impossible) for millions of images.
  • Waste of network bandwidth.
  • Can't catch errors for the time between two consecutive runs of the cleanup task.

2. Handle it in your application

If an image does not exist, we can replace it with a new one.

Another way to handle this issue is by listening to the error event that gets fired when the image fails to load. In HTML, this can be done with the onerror attribute of the <img> tag.

<img src="http://example.com/non-existent-image.jpg" />

If the original image fails to load, then it is replaced by the image mentioned in the onerror attribute handler.

Similar handling can be done in mobile apps as well.

Advantages

  • Can handle data issues in real-time.
  • No need for periodic checks.

Disadvantages

  • Won’t work for images loaded as background (at least for websites).
  • Problems may continue in older versions of your website or application that cannot be updated with the new code.
  • Different code for different platforms.

3. Handle it on your image server

If the image does not exist, then the server should not send the error at all.

Your image server knows if an image does not exist and sends a 404 Not Found HTTP status code to the client. Instead, the server itself could replace it with a default image, correct the HTTP status code and then send it to the browser or the application.

Advantages

  • Works in real time without any periodic checks.
  • No handling needed on any application or any version of any application.
  • Works for all kinds of images.

Disadvantages

  • You need to build a server that can handle this rerouting for you.
  • Difficult, if not impossible, to get it working with simple image delivery setups like CDN + S3 storage.

4. Handle it using a third-party image server like ImageKit.io

ImageKit.io automatically provides server-side handling of non-existent images. Using ImageKit’s URL-based transformations, you can specify the default image that should be delivered, if the original image does not exist, with the original image URL itself. To give an example,

<!-- The non-existent image URL -->
<img src="https://ik.imagekit.io/demo/img/non_existent_image.jpg" />

<!-- Specifying the default image to be displayed in the URL -->
<img src="https://ik.imagekit.io/demo/img/tr:di-medium_cafe_B1iTdD0C.jpg/non_existent_image.jpg" />

The default image is specified using the di- parameter in the URL. In this case, the default image is from a cafe.

Deliver a default image, the one on the right, instead of the broken image, the one on the left.
Deliver a default image, the one on the right, instead of the broken image, the one on the left.

Being a URL-transformation, this gives you the flexibility to specify a different default image for different kinds of images without having to write any code to handle the error cases.

You can read more about handling of non-existent images or default images using ImageKit here.

Considerations for image caching in error cases

Default images sent instead of a non-existent image should not be cached at all, or if it is cached, then the cache duration should be small, preferably a few hours. This leaves an opportunity for the non-existent image to be “fixed” or made available. When this happens, then the correct image would start getting delivered to the users automatically.

However, if the image is not expected to be fixed, then the cache duration can be longer.

Considerations for response code in error cases

If you wish to handle the error case in your application, then the image request should be returned with a 404 status code for the onerror to work.

If you are delivering the default image instead of a broken image from the server, then the response code can be 302 Temporarily Moved (ideally to prevent caching on intermediate layers like CDN, but handling with success and error handlers in application is impaired) or 200 OK (caching on intermediate layers can be controlled with caching headers)


Since images form a critical part of our application, ensuring that the UX is not broken because of data issues with images is equally important. I hope the above techniques will help in ensuring a better experience for your users on your website and app.

Drop a comment if you have any ideas on handling images that no longer exist on a web application.