RE: Media Queries and optimizing what data gets transferred

> Date: Wed, 30 Jan 2013 09:46:21 +0200
> From: hsivonen@iki.fi
...
> > So, proposal as it stands is:
> >
> > Add an "async" (or "defer", whatever is closest to the semantics we're
> > trying to achieve) to <link>.  I guess currently only rel=stylesheet
> > pays attention to it, but other rels can opt-in as well on their own.
> > (Add it to <style> as well, with the semantics applying to @import'd
> > sheets? Maybe confusing, since you wouldnt' want to automatically
> > opt-in the @import rules in a <link async> to be async as well.
> > Perhaps we can add this to the @import grammar instead.)
> >
> > An async stylesheet never blocks the parsing or JS thread, or any
> > other loads started during page load (or just from the parser?). When
> > the network queue is empty, the browser begins requesting async
> > stylesheets.  (Replace this with appropriately technical language
> > cripped from <script>'s loading algo, if that would help.)
> >
> > A browser MAY defer indefinitely the loading of an async stylesheet
> > whose media query is false.
> >
> > An async stylesheet does not expose a CSSOM at any time, whether it's
> > loaded or not, until the author requests it.  This includes showing up
> > in the document.styleSheets list, etc.  The author can request the
> > CSSOM be exposed by calling LinkElement#requestCSSOM(callback?) (name
> > pending).  If the stylesheet is not yet loaded, it puts a load on the
> > event queue.  It then puts an action on the event queue to expose the
> > CSSOM, and if the optional callback was provided, call the callback,
> > passing it the CSSStyleSheet object thus generated.
> >
> > If this sounds good, I'll put it on the wiki.  We can discuss it
> > internally, then I'll send it to WHATWG for further review and request
> > for addition.
> 
> Sounds good to me if you change "A browser MAY defer indefinitely the
> loading of an async stylesheet whose media query is false." to "A
> browser MUST defer the loading of an async stylesheet until media
> query is true."

I disagree.  It is enough that the async stylesheet does not expose a CSSOM
until requested.  There is no need at all to be prescriptive about the order
that the UA chooses to load the resources, and I suggest that any such
wording be non-normative and just an example of what a UA may do to
optimize typical response times.
 
> Otherwise, you fail to make a promise, and if you don't promise,
> authors who want a promise will still seek solutions where they can
> control in their JS or server-side code what decisions are made.

Why would you want the content author dictating the load order?  The
UA may well know better: it might have a style sheet cached locally that
is can productively use, or it might guess that a media query change will
occur before all the other page resources are loaded, etc.

cheers
Fred

 		 	   		  

Received on Wednesday, 30 January 2013 11:14:24 UTC