
Originally Posted by
samanime
I think for overall functionality (whether it needs the script at all or not), that's probably better left to server-side (to prevent a large script from needlessly being sent).
Why should the server know about the screen res?
It's also a tiny script.
What this doesn't do is stop someone whose media is "handheld" from downloading some ginormous script
It could, You just can't load all of your scripts the usual way with <script></script>. e.g.
Code:
function require(path) {
try{
document.write('<script type="text/javascript" src="'+path+'"><\/script>');
} catch(e) {
var script = document.createElement('script');
script.src = path;
document.getElementsByTagName('head')[0].appendChild(script);
}
}
if (isMedia("screen and (max-width:800px)"){
require('/js/small-screen.js');
}
else {
require('/js/big-screen.js');
}
Edit: As Stormrider said ^
The script looks really useful.
It reminds me a lot of @JimmyP's ie detection script http://james.padolsey.com/javascript...onal-comments/
Injecting html into the doc to test support for a feature.
I love how these different patterns give people inspiration to think outside the square.
The same thing happened with the Module Pattern.
Bookmarks