I have a question about CSS media queries. I’d like to know if CSS media queries affects the number of http requests on the web page.
For example:
<link rel="stylesheet" href="file.css" media="only screen and (max-width: 640px)">
<link rel="stylesheet" href="file2.css" media="only screen and (max-width: 960px)">
<link rel="stylesheet" href="file3.css" media="only screen and (max-device-width: 480px)">
My question is: From my understanding of CSS media queries, if the visitor of the web page is using one device/monitor then the other stylesheets don’t apply. If the media query doesn’t apply to the visitor, then does it still add an http request to the page?
HTTP requests are made to download all stylesheets linked, regardless of what is in their
mediaattribute, so:would result in two HTTP requests. See section 4.12.5.11 of the working draft of the HTML5 spec for
links: http://www.w3.org/html/wg/drafts/html/master/links.html#link-type-stylesheetTo minimize HTTP requests, combine your stylesheets into a single file and wrap them in
@media (max-width:767px){ ... }, etc.