scottjehl/picturefill — pull request #234 by Schepp (2014-05-12 23:10:15+00:00)
Title: Observe mutations

Hey guys,

a few days back I twittered the following:

@scottjehl Have you guys thought about adding Mutation Observers in order to react to script-induced changes to picturefill's sources?

— Christian Schaefer (@derSchepp) 28. April 2014

@scottjehl Maybe I can manage to get my act together and contribute with a pull request not too soon.

— Christian Schaefer (@derSchepp) 28. April 2014

So here it is! `picturefill` supercharged with [Mutation Observers](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver). These things observe the DOM and detect any newly injected `picture` or `img` nodes and has the polyfill process them automatically. The same happens if someone changes the source attributes of existing images. Behavior-wise this brings `picturefill`a lot closer to native.

Older browsers that do not yet support Mutation Observers (see [support tables](http://caniuse.com/mutationobserver)) will use the older [Mutation Events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Mutation_events). This includes IE9 and IE10. Mutation Events are only partially supported by Android 2.2 - 4.3 (only detects new nodes, no modified attributes). Feature tests [over here](https://github.com/mwbrooks/mutation-event-tests).

All other browsers, like <= IE8 fall back to the state we already have right now.

I really hope you like that feature addition!

Cheers

Christian