A responsive image polyfill for , srcset, sizes, and more

Overview

Picturefill

A responsive image polyfill.

build-status Join Slack channel picturefill on npm

Picturefill has three versions:

  • Version 1 mimics the Picture element pattern with span elements. It is no longer maintained.
  • Version 2 is a lightweight polyfill of the Picture element draft specification.
  • Version 3.0.3 is the current stable release.

Usage, Demos, Docs

To find out how to use Picturefill, visit the project site.

The gotchas

Be it browser issues, the responsive images specifications, or Picturefill itself, there are a couple gotchas you should be aware of when working with Picturefill:

  • Firefox 38 and 39 has some bugs [1] [2] [3] where images won't update on screen resize. These issues are addressed by Picturefill 3.0.0, and was fixed in Firefox 41.

  • Per the picture spec, using % isn't allowed in the sizes attribute. Using % will fallback to 100vw.

  • Trying to use the src attribute in a browser that doesn't support picture natively can result in a double download. To avoid this, don't use the src attribute on the img tag:

<picture>
    <source srcset="../img/sample.svg" media="(min-width: 768px)" />
    <img srcset="default.png" alt="Sample pic" />
</picture>
  • If you only want to have an image show up at certain sizes, and not show up at others, you will need to use a transparent placeholder gif:
<picture>
    <source srcset="../img/sample.svg" media="(min-width: 768px)" />
    <img srcset="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        alt="Sample pic" />
</picture>

Contributing

For information on how to contribute code to Picturefill, check out CONTRIBUTING.md

Issues

If you find a bug in Picturefill, please add it to the issue tracker

Discussion

Picturefill discussion takes place via Slack. For an invitation, visit https://pf-slackin.herokuapp.com/

Support

There are currently no known unsupported browsers, provided that you use the markup patterns provided.

Comments
  • IE8 doesn't appear to work

    IE8 doesn't appear to work

    I am having an issue with IE8 were picturefill doesn't appear to be working, I thought it was my code but it also doesn't function as expected on the demo. Is this a known issue?

    image

    opened by JohnCashmore 39
  • refactor branch: split source into files

    refactor branch: split source into files

    Proposed breakout:

    • picturefill.core.js : picture markup polyfill with media and srcset attribute support
    • picturefill.sizes.js : extension with sizes attribute support (with feature detect?)
    • picturefill.type.js : extension with type attribute support

    Any others?

    opened by scottjehl 38
  • Planning for <picture> markup

    Planning for markup

    Now that srcset has landed in browsers and picture is coming soon, it'd be a good time to get Picturefill back to its original goal as a simple polyfill for the standard markup.

    This thread can be used for planning that out, as there are a number of things to consider. Here are a few off the top of my head:

    • IE9 (maybe 10 too, can't remember - and desktop and mobile versions) does not recognize source elements if they don't have a video or audio element parent. We'll need to find a way to work around this one - ideally without changing the markup pattern to accommodate, but that may not be possible. Here's how I worked around it in the past (note: gross) https://github.com/scottjehl/picturefill/tree/original-picture-markup
    • I think it'd be good if we refactor a bit to get the code more modular and extensible.
    • I think it might be nice if source[srcset] handling was written as an excludable extension to Picturefill, so people can include it in the build if needed.

    Also, we should get this thing running on grunt, updated on Bower, and unit tested.

    Woo!

    opened by scottjehl 29
  • Removed unnecessary method caching

    Removed unnecessary method caching

    • .call() is more expensive than just calling the method.
    • All of the three methods were already used normally elsewhere, this commit will keep it consistent.
    • This will help reduce errors with object-fit-images (first note here: https://github.com/bfred-it/object-fit-images/blob/gh-pages/detailed-support-tables.md#object-fit-images--srcset)
    Ready for review Refactor 
    opened by fregante 27
  • Main refactoring for performance and Spec compilance + many bugfixes and new unit tests

    Main refactoring for performance and Spec compilance + many bugfixes and new unit tests

    New features:

    • simple mediaqueries are now also supported in IE8
    • Performance (Resize-Performance, "Scales better", Network-Performance see below)
    • Does not download a new image,
      • if it has already a better candidate from the same set (maybe needs an option, some people might not understand this and think it's a bug)
      • while window is resized
    • Loads new candidates in background for "smooth" Transition between candidates
    • addDimensions (option)
    • resQuantifier (option)
    • the elements parameter can now also handle a DOM node (if an img is passed this is polyfilled, if another element is used this is used as the context)
    • Mutationobserver (plugin)
    • improved errormessages for bad descriptors, bad sizes and wrong source positioning

    Following is the list of fixed bugs in your bug tracker by my changes.

    Fixed issues: https://github.com/scottjehl/picturefill/issues/333 https://github.com/scottjehl/picturefill/issues/332 https://github.com/scottjehl/picturefill/issues/331 https://github.com/scottjehl/picturefill/issues/329 https://github.com/scottjehl/picturefill/issues/327 https://github.com/scottjehl/picturefill/issues/322 https://github.com/scottjehl/picturefill/issues/318 https://github.com/scottjehl/picturefill/issues/314 https://github.com/scottjehl/picturefill/issues/313 https://github.com/scottjehl/picturefill/issues/311 https://github.com/scottjehl/picturefill/issues/309 https://github.com/scottjehl/picturefill/issues/304 https://github.com/scottjehl/picturefill/issues/303 https://github.com/scottjehl/picturefill/issues/292 https://github.com/scottjehl/picturefill/issues/270 https://github.com/scottjehl/picturefill/issues/266 https://github.com/scottjehl/picturefill/issues/244 https://github.com/scottjehl/picturefill/issues/142 https://github.com/scottjehl/picturefill/issues/263 https://github.com/scottjehl/picturefill/issues/317

    opened by aFarkas 26
  • Picturefill 'disturbed' by broken / incomplete SRCSET implementation in safari 7.1, 6.2, IOS8, and Chrome 37

    Picturefill 'disturbed' by broken / incomplete SRCSET implementation in safari 7.1, 6.2, IOS8, and Chrome 37

    These browsers feature SRCSET natively in IMG tag but with an incomplete implementation only X no W SIZES ??? So the SRCSET attribute is removed (i assume by browser) which my lightbox-script rely on for zoom on click (I use an higher res picture then). Firefox 32.0.2 still works as expected, IOS 7.x Safari 7.01, 6.1.x, too.

    Update: The SRCSET attribute is removed by picture fill. Removing the picturefill.js keeps the SRCSET and my lightbox-zoom can work with the sources provided by SRCSET.

    BTW, additional pitfall: using multiple sources with W on these incomplete native implementation only loads the url from the SRC attribute (the smallest mobile / fallback img in my case).

    Spec mismatch Critical 
    opened by ffechner 26
  • 2x image size behaviour does not match native Chrome

    2x image size behaviour does not match native Chrome

    <img srcset="logo.png, [email protected] 2x"> With the above markup and no size attributes or CSS sizing, non-Chrome browsers display the 2x image at the original size, so that it appears twice as big when on a 2x display.

    In Chrome however the 2x image is displayed at half size, so that it appears to be the same size as the 1x image.

    The same issue occurs with any of these too: <img srcset="logo.png 1x, [email protected] 2x"> <img src="logo.png" srcset="logo.png, [email protected] 2x"> <img src="logo.png" srcset="logo.png 1x, [email protected] 2x">

    Also, with this markup a 1x display connected to a 2x device (external monitor on a Retina MacBook Pro) will load the 2x image: <img src="logo.png" srcset="[email protected] 2x">

    Chrome continues to work fine in that situation though.

    I'm in a situation where I cannot apply a size with HTML or CSS to constrain the 2x image to the original size, so that's out of the question. I could use max-width/height for some constraint, but if the 1x image is smaller than that size then the 2x version will still look bigger.

    Spec mismatch Critical 
    opened by JakePT 25
  • Picturefill complete event?

    Picturefill complete event?

    Might it be possible to have picturefill give notice as to when it's done?

    I'm wanting to use PF instead of the background image property because - as far as I know - that property doesn't make an intelligent decisions. That is, it will use the same (often too large) background image regardless of viewport.

    I've come up with a solution that fakes the background image property (at least for our purposes). It works. But feels kinda hack-y. If only there was an "I'm done, Your turn now" event or similar, that would be better / cleaner.

    Otherwise, great product. It's pure #BadAss. Thanks for sharing.

    opened by AlchemyUnited 24
  • Images don't show up in IE8 with 1x/2x syntax

    Images don't show up in IE8 with 1x/2x syntax

    Hi,

    I encountered a problem in Internet Explorer 8 (and below).

    When using the syntax to display retina images, no images appear in the browser.

    <img srcset="http://placehold.it/300x150 1x, http://placehold.it/600x300 2x" alt="Retina" />
    

    I don't see any errors - the code adding the src to the img tag just doesn't seem to be applied.

    Here is a fiddle with the test code : http://jsfiddle.net/oilvier/VdbT4/ (I used the code from the demo site to compare with a case where it's working)

    If you watch it in IE8, you'll need this link, as jsfiddle interface is not displaying well in IE8 : http://fiddle.jshell.net/oilvier/VdbT4/show/light/

    Spec mismatch Needs info 
    opened by oilvier 23
  • Consider polyfilling the JS/DOM api portions

    Consider polyfilling the JS/DOM api portions

    Per a request from the FT, it'd be useful for them if we populated properties like window.HTMLPictureElement after polyfilling support for it.

    https://github.com/Financial-Times/polyfill-service/pull/448

    Worth discussing if this will cause any difficulties with how things are set up internally, particularly on subsequent runs in a page?

    Needs info Discussion 
    opened by scottjehl 20
  • Suggestion: Add Impact on SEO to gotchas in README.md

    Suggestion: Add Impact on SEO to gotchas in README.md

    Currently, probably the biggest gotcha (in many cases) to using Picturefill v2+ is that it renders all images unindexible by Google. For many sites this may have serious SEO implications, so I think this should be clearly stated in the README. This same issue obviously also means anybody with JavaScript disabled will see no images at all, so again, I think this deserves adding.

    opened by Undistraction 20
  • Archive/Sunset This Project

    Archive/Sunset This Project

    As pointed out to me recently by @yoavweiss, this project's (THANKFULLY!!) no longer needed and can be archived.

    I'll go ahead with that shortly but wanted to make a note of it here first for anyone listening. Thanks!

    opened by scottjehl 3
Releases(3.0.3)
  • 3.0.3(Mar 20, 2017)

    JavaScript module sizes and how they're ludicrous is a hot topic on the internet these days, eh? Well, we here at Picturefill are not ones to miss out on a good trend. Thanks to @gpittarelli we've reduced the installed size of Picturefill by about 98%.

    For those of you concerned that this means 98% of your responsive images won't be polyfilled, fear not. We're only being polite to your disk space and not installing a full copy of the examples directory (and various other small fried fish, by comparison) each time you install Picturefill. These examples are, of course, available on the wider interwebs, should you need them.

    Official Release Notes ™:

    • add .npmignore file (via #674)
    Source code(tar.gz)
    Source code(zip)
  • 3.0.2(Feb 12, 2016)

    • documented polyfill plugins
    • force FF to re-select image candidate on window.resize (including srcset only)
    • proper sizes detection for Safari 9.x
    Source code(tar.gz)
    Source code(zip)
  • 3.0.1(Sep 30, 2015)

  • 3.0.0(Sep 30, 2015)

    • Spec-accurate parsers for srcset and sizes
    • Close matching of native behavior in terms of source selection
    • A number of fixes for first-wave implementation issues, such as https://bugzilla.mozilla.org/show_bug.cgi?id=1135812
    • A significantly more robust test suite
    Source code(tar.gz)
    Source code(zip)
  • 3.0.0-rc1(Sep 8, 2015)

  • 3.0.0-beta1(Jul 10, 2015)

    Picturefill 3.0 boasts a deadly accurate set of parsers, and matches a number of native behaviors that Picturefill 2.x didn’t—but also meant a near-complete rewrite.

    That means we need testers.

    Give the Picturefill 3.0.0 beta a try, and let us know if you run into any issues!

    Source code(tar.gz)
    Source code(zip)
  • 2.3.1(Apr 27, 2015)

    This release fixes a critical issue with Picturefill’s currentSrc support test. This issue caused errors in both the Spartan and WebKit nightlies.

    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Mar 23, 2015)

    Changes from Picturefill 2.3 Beta:

    Spec Matching

    • Invalid sizes values now fall back to 100vw default (f379528073d875089bc594900079b09184dd4f69)

    Bugs

    • Fixes a potential race condition when using type (3fba68de8b0df200e36b56dcfb01f89e09f8d4d0)
    • Prevents a fatal error in IE8 when assigning an undefined width (d1f5a1fd550e30545f7b4c66b94e4838bab1a720)
    • Prevent IE10/11 from setting an inherent width of zero on SVGs (742c66c0a93e7d417e58f1a50238371c3c1d6ef6)
    • Fixes an error that prevented Picturefill from being handled as a named AMD module (a5859fb564fd32d4ca3643277ccb35025a93214a)
    Source code(tar.gz)
    Source code(zip)
  • 2.3.0-beta(Feb 11, 2015)

    Along with assorted bugfixes and performance improvements, the following major issues have been addressed with this release:

    Added support detection for the following image types: jpxr, jpg2000, and apng. Image format support can now be handled using extensions. SVG and WebP remain a part of the Picturefill core, so as not to break existing implementations.

    Support for intrinsic image dimensions Picturefill now matches native behavior in terms of an image’s inherent size: when served at “2x,” the image is displayed at half of its source’s inherent size. Note that this can and must be overrideable via CSS.

    Picturefill is now a named AMD module, and uses AMD/CommonJS module factory also in native supporting browsers.

    Picturefill has a team now Everyone join me in welcoming the team responsible for the lion’s share of work that went into this release, and many more to come.

    Did someone just whisper “Picturefill 3?” I thought I just heard someone whisper “Picturefill 3.” Weird.

    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Nov 19, 2014)

  • 2.2.0-beta(Oct 30, 2014)

  • 2.1.0(Jul 25, 2014)

    Downloads, documentation, and examples: http://picturefill.responsiveimages.org

    • Matches the source parsing algorithm outlined in the spec (find all img, check for parent picture elements, process any/all source elements until finding the img that invoked it all)
    • Allows use of the extended srcset syntax without an explicit sizes attribute, per the spec
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0-beta2(Jul 15, 2014)

    Downloads, documentation, and examples: http://picturefill.responsiveimages.org

    • Matches the source parsing algorithm outlined in the spec (find all img, check for parent picture elements, process any/all source elements until finding the img that invoked it all)
    • Allows use of the extended srcset syntax without an explicit sizes attribute, per the spec
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0-beta(Jun 3, 2014)

    Downloads, documentation, and examples: http://picturefill.responsiveimages.org

    Release Notes:

    • Numerous bugfixes
    • A number of developer conveniences, such as an included editor config file and styleguide-enforcing Grunt task
    • A vastly improved srcset parser that should—hopefully—line up one-to-one with the parsing algorithm from the spec
    • A more robust test suite
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(May 2, 2014)

  • 2.0.0-beta(Apr 23, 2014)

    Downloads, documentation, examples: http://scottjehl.github.io/picturefill/

    Release notes:

    • Improved browser support: Picturefill now works in IE6+ (the alpha had an error in IE7 and 8 that caused it to fail to load an image)
    • Changes to make polyfill behavior conform more closely to the specification
    • Picturefill JavaScript API documentation added
    • Demo page improvements
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-alpha(Apr 17, 2014)

  • 1.2.1(Nov 18, 2013)

Owner
Scott Jehl
Author of Responsible Responsive Design (A Book Apart). Designer/Developer at @filamentgroup. I love to surf. surf30a.com
Scott Jehl
EventSource polyfill

EventSource polyfill - https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events Installing: You can get the code from npm or

Viktor 1.9k Jan 9, 2023
Drag and drop library for two-dimensional, resizable and responsive lists

GridList Drag and drop library for a two-dimensional resizable and responsive list of items Demo: http://hootsuite.github.io/grid/ The GridList librar

Hootsuite 3.6k Dec 14, 2022
a responsive equal heights plugin

jquery.matchHeight.js matchHeight makes the height of all selected elements exactly equal brm.io/jquery-match-height Demo - Features - Gallery - Insta

null 3.1k Jan 5, 2023
NodeJS application to upload an image to a S3 Bucket on AWS.

node-upload-image-to-s3-bucket NodeJS application to upload an image to a S3 Bucket on AWS. How it works: You must make a POST request to /upload-imag

Rafael Silva de Lima 6 Sep 28, 2022
Gmail-like client-side drafts and bit more. Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings and other disasters.

Sisyphus Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings and other disasters. Descriptio

Alexander Kaupanin 2k Dec 8, 2022
A lightweight jQuery plugin for collapsing and expanding long blocks of text with "Read more" and "Close" links.

Readmore.js V3 alpha I am deprecating the 2.x version of Readmore.js. A new version is coming soon! Check it out and help me test it! Readmore.js A sm

Jed Foster 1.5k Nov 30, 2022
A high-performance, dependency-free library for animated filtering, sorting, insertion, removal and more

MixItUp 3 MixItUp is a high-performance, dependency-free library for animated DOM manipulation, giving you the power to filter, sort, add and remove D

Patrick Kunka 4.5k Dec 24, 2022
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.

List.js Perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on

Jonny Strömberg 10.9k Jan 1, 2023
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

JavaScript Algorithms and Data Structures This repository contains JavaScript based examples of many popular algorithms and data structures. Each algo

Oleksii Trekhleb 158k Dec 31, 2022
FriendAdvisor is a mobile app with a focus on allowing friends and family to coordinate and receive text notifications about upcoming group events.

FriendAdvisor is a mobile app with a focus on allowing friends and family to coordinate and receive text notifications about upcoming group events.

Brad Johnson 4 Sep 29, 2022
Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code

Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code.

당근마켓 31 Dec 8, 2022
JavaScript Survey and Form Library

SurveyJS is a JavaScript Survey and Form Library. SurveyJS is a modern way to add surveys and forms to your website. It has versions for Angular, jQue

SurveyJS 3.5k Jan 1, 2023
Extensive math expression evaluator library for JavaScript and Node.js

?? Homepage Fcaljs is an extensive math expression evaluator library for JavaScript and Node.js. Using fcal, you can perform basic arithmetic, percent

Santhosh Kumar 93 Dec 19, 2022
Components for interactive scientific writing, reactive documents and explorable explanations.

@curvenote/article The goal of @curvenote/article is to provide web-components for interactive scientific writing, reactive documents and explorable e

curvenote 142 Dec 24, 2022
Create explorable explanations and interactive essays.

Tutorials | Examples | Docs | Chatroom | Mailing list | Twitter What is Idyll? For an introduction to Idyll, API reference, examples, and tutorials, p

Idyll 1.9k Dec 27, 2022
Browser fingerprinting library with the highest accuracy and stability.

FingerprintJS is a browser fingerprinting library that queries browser attributes and computes a hashed visitor identifier from them. Unlike cookies a

FingerprintJS 18.1k Dec 31, 2022
autoNumeric is a standalone library that provides live as-you-type formatting for international numbers and currencies.

What is autoNumeric? autoNumeric is a standalone Javascript library that provides live as-you-type formatting for international numbers and currencies

AutoNumeric 1.7k Dec 16, 2022
Bookmarklet to remove sticky elements and restore scrolling to web pages!

Bookmarklet to remove sticky elements and restore scrolling to web pages!

Tim Martin 648 Dec 29, 2022
Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Superalgos 3.1k Jan 1, 2023