Skip to content

Instantly share code, notes, and snippets.

@bencallahan
Created May 2, 2012 20:25
Show Gist options
  • Select an option

  • Save bencallahan/2580149 to your computer and use it in GitHub Desktop.

Select an option

Save bencallahan/2580149 to your computer and use it in GitHub Desktop.
Responsive Retrofitting: CSS Loading: Option 2
<!--
This is a series of gists comparing options for how to load CSS for a large
responsive retrofit. The requirements for this are as follows:
1. limit to one http request for CSS
2. keep the size of this CSS request as minimal as possible
3. serve only the original CSS to large resolutions (>= 980)
4. serve only the new "responsive" CSS to smaller resolutions (< 980)
5. serve only the original CSS to browsers that don't support media queries
Because this is a retrofit, we're not touching the original CSS. So, smaller
screen devices will have unique CSS. We can't touch the original CSS files,
so we need to do this in a way that keeps these mutually exclusive.
-->
<html class="no-mediaquery no-js">
<head>
<script src="/js/media-query-check.js">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
</html>
/* this is a SCSS file which aggregates the necessary components for all
screens */
/* if JavaScript is disabled OR media queries aren't supported */
.no-mediaquery {
@import "original";
}
@media (max-width: 500px) {
@import "small";
}
@media (max-width: 979px) {
@import "medium";
}
@media (min-width: 980px) {
@import "original";
}
@bencallahan

Copy link
Copy Markdown
Author

Requirements:

  • passes 1
  • falies 2 (all the styles are in the single CSS file—although not all will be used)
  • passes 3
  • mostly passes 4 (fails for small screens that don't support Media Queries—see requirement 5)
  • passes 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment