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

推荐订阅源

Y
Y Combinator Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threat Research - Cisco Blogs
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
博客园 - 【当耐特】
AWS News Blog
AWS News Blog
U
Unit 42
V
Vulnerabilities – Threatpost
P
Privacy International News Feed
T
Tor Project blog
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
Latest news
Latest news
GbyAI
GbyAI
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Hacker News: Ask HN
Hacker News: Ask HN
美团技术团队
N
News | PayPal Newsroom
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
The GitHub Blog
The GitHub Blog
V
V2EX
N
News and Events Feed by Topic
T
Troy Hunt's Blog
Security Latest
Security Latest
博客园 - 叶小钗
P
Palo Alto Networks Blog

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 Deliver Responsive Images Across Multiple Devices
Manu Chaudhary · 2017-06-11 · via ImageKit.io Blog

According to the data from HTTP archive, 64% of a website’s page weight, on an average, is made up of images. With mobile traffic surpassing desktop traffic, it has now become even more crucial to optimize images for different device sizes.

Ideally, you would like to serve images that are resized to match the user’s viewport dimensions. Without a means to do this, you will sometimes have to send a larger image than what is actually required.

This means that the user has to download more data than he should be downloading, which in turn slows down the page load. This is a wastage of time, bandwidth, and money which impacts the overall user experience, and hence, conversions on your website.

Let’s say you want to have a full-width banner on the top of your website. A 1280px wide banner image would work well on a desktop device for this purpose. But the same image is too big to use as a full-width banner on a mobile device which has 320px wide screen.

In short, we want the browser to load the correct image based on:

1. The viewport dimensions
Whether the viewport is 1280px wide or 640px or 320px.

2. The size of the image relative to the viewport
Whether the image occupies 100% of the available width or 50% or 33%. In our example of the full-width banner above, the image occupies 100% of the available width.

Now that we have identified the problem, there are a couple of ways to get the solution:

- Using client hints (DPR, Width, and Viewport-Width) — very less support
- Using srcset and sizes attributes of the img HTML tag — supported by all major browsers

We will talk about the srcset and sizes attributes in this article.

Before discussing the actual implementation, let’s talk about what is known to you as a developer at the time of writing the code, and what is known to the browser at the time of actual rendering of the images.

As a developer, you know two things that the browser does not know at the time of triggering image load (which is before the CSS is parsed):

1. The size of the image relative to the viewport
This depends on the layout that you are trying to build on your website as discussed above in the full-width banner example.

2. The URLs of different sizes of the image
Now that you need different images for different viewport dimensions, each image should be accessible individually on a unique URL.

On the other hand, as a developer, you have no clue about the actual viewport dimensions. This is something which is available only to the browsers at the time of actual rendering.

So, if somehow we pass on the two pieces of information that we know as a developer to the browser, then the browser has all the information needed to select and load the appropriate image.

This is what the srcset and sizes attributes are all about!

The srcset attribute tells the browser the URLs of different sizes of a particular image and the width of each image, using the w parameter

srcset="large.jpg 1024w,
        medium.jpg 640w,
        small.jpg 320w"

In the above example, we are basically telling the browser that we have 3 image sizes with us. large.jpg is 1024px wide, medium.jpg is 640px wide and small.jpg is 320px wide.

The sizes attribute tells browser about how the image will be laid out on our website. It uses the length parameter

sizes="[media query] [length], [media query] [length] ..."

From the list of sizes specified, the browser goes over each media query until it finds the one that evaluates to true and uses the length specified against that media query as the final width of the image to be rendered.

Without this additional styling information specified in sizes, the browser would have had to wait for the CSS to be downloaded and parsed. With the sizes attribute, we are simply providing this crucial bit of information in advance.

Once the width of the image to be rendered has been identified from the sizes attribute, the browser selects the most appropriate image from the list specified using the srcset attribute and starts to load that image.

We have set up a demo page to illustrate the use of srcset and sizes attributes using ImageKit’s URL-based transformations. The page can be accessed here.

With ImageKit’s URL based transformation, you don’t have to create and manage different sized assets on your server. You can create them on-the-fly and implement responsive images. All you have to do is identify what all sizes do you need and just write the markup.

Let’s have a look at the code from our example, which demonstrates the use of srcset and sizes attributes.

Sample code from the Responsive image demo page — https://imagekit.io/demo/responsive-images-with-srcset-and-sizes
Sample code from the Responsive image demo page — https://imagekit.io/demo/responsive-images-with-srcset-and-sizes

Here, we are providing 3 different image URLs and the width of each image via the srcset attribute. The three images have widths 500px, 800px and 1024px which is obtained by using the width transformation tr:w- in the URL.

Then we have used the sizes attribute to provide the final width of the rendered image. With the value (min-width: 1024px) 1024px, 100vw we have actually specified two media query and length sets.

The first set states that whenever the viewport width is equal to or greater than 1024px, then the image takes up exactly 1024px. In other cases (i.e. when the viewport width is less than 1024px), then the image takes up 100% of the viewport width (specified using 100vw).

Sample layouts on two devices that would match the layout specified using the ‘sizes’ attribute above
Sample layouts on two devices that would match the layout specified using the ‘sizes’ attribute above

If you check the demo page and resize the window you will notice:

1. At 400px, the browser uses the image with width 500px
/tr:w-500/responsive_images_srcset_sizes_assets/big/1.jpeg

2. At 700px, the browser uses the image with width 800px
/tr:w-800/responsive_images_srcset_sizes_assets/big/1.jpeg

3. Above 800px, the browser uses the image with width 1024px
/tr:w-1024/responsive_images_srcset_sizes_assets/big/1.jpeg

The browser automatically picks the best image based on actual viewport width, pixel density (and possibly based on bandwidth limitations or user preference).

Notice that while using srcset and sizes, you could end up with a huge list of potential source image files, hence you should employ a good strategy to choose breakpoints to keep the markup simple.

This content about responsive images was originally published on ImageKit's medium blog as "How to deliver responsive images across multiple devices"


Please do share your thoughts about this in the comments section below. You can try ImageKit.io by registering for free and implement cross-device responsive images in your project today.