Created
April 6, 2011 05:13
-
-
Save nathansmith/905177 to your computer and use it in GitHub Desktop.
Conditionally serve CSS to screen widths that can handle it. With a fallback for when JavaScript is disabled and/or not supported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title> | |
Adaptive Layout Idea | |
</title> | |
<link rel="stylesheet" href="basic_defaults.css" /> | |
<noscript> | |
<link rel="stylesheet" href="fallback.css" /> | |
</noscript> | |
<script src="small_file_to_determine_css_based_on_width.js"></script> | |
</head> | |
<body> | |
<p> | |
Hello. Don't look at me. Magic is up above! | |
</p> | |
<script src="js_library_of_choice.js"></script> | |
<script src="other_site_specific.js"></script> | |
</body> | |
</html> |
I guess, but so could un-handled CSS download or unrecognized media query. As with anything in web development, always test your code. :)
Well I'm just curious how likely it is. You're far more experienced with JS than myself. Does keeping the width calculation confined to that first script help avoid possible issues in the other scripts? Ensuring small_file_to_determine_css_based_on_width.js gets loaded first should help, right?
Yes, the width calculation is sandboxed and can't affect other scripts...
Ah, excellent. Looking forward to testing this out soon. Seems much more flexible than media queries. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great idea. Could un-handled errors completely break your layout though?