sjbuysse
sjbuysse

Reputation: 4104

How to precompile picturefill with rails asset pipeline

I'm using the polyfill picturefill to add support for the img attributes srcset and sizes in browsers like IE. This polyfill doesn't work when precompiling the javascript in the asset pipeline in rails. It DOES work when I exclude it from the pipeline and include it (picturefill) at the end of my <body> tag.

My guess is that picturefill gets executed before the page has fully been loaded (with all 'img' tags). Is this correct? And if so, why didn't the authors add something like a document.ready() event? Is there a way I can solve this more elegant than including the whole script at the end of my body? Adding the script like this seems like a huge performance hit.

Upvotes: 0

Views: 101

Answers (1)

sjbuysse
sjbuysse

Reputation: 4104

I found a solution, http://reed.github.io/turbolinks-compatibility/picturefill.html

it looks like turbolinks creates a page:load event, and we can use that event to call the picturefill script

Upvotes: 0

Related Questions