3 ms·
Why stop at images only? A more general solution using CSS-like media queries would be much preferable; with a general solution it would be possible to serve al
by hrjet 12y ago
Why stop at images only? A more general solution using CSS-like media queries would be much preferable; with a general solution it would be possible to serve all sorts of assets (CSS, JS, Images, Video, etc) tailored to the display device and network connection.
- eurleif 12y ago<picture> is responsive; when you change the viewport's width, the browser can load a differently-sized version of the image. How would JS be made responsive like that? Once one version of a script is loaded, you can't magically replace it with a difference version. Of course, you could limit the media queries that could be used with JavaScript, but then your general solution isn't really so general anymore. And there's already a way to dynamically load scripts, so we don't really need another way to do that: <script> if (blah) { document.write('<script src="a.js">'); } else { document.write('<script src="b.js">'); } </script> And there's also already a way dynamically load CSS (using media queries, even): <style> @import url(a.css) (max-width: 800px); @import url(b.css) (min-width: 801px); </style>
- hrjet 12y agoGood point about JS. But there are potentially more types of media (audio, video, html via frames, etc). Even if a general solution isn't applicable to JS, it can have lots of other uses.
- tg3 12y agothe <picture> tag is set up very similarly to the audio and video tags, so I think that even if this specific solution isn't general, the pattern can be applied generally to other types of media.
- eurleif 12y ago>html via frames That has the same problem as JS, especially when you realize that framed pages on the same domain can interact with the parent's DOM.
- paulirish 12y agohttps://developer.mozilla.org/en-US/docs/Web/API/Window.matchMedia https://developer.mozilla.org/en-US/docs/Web/API/Window.matc...