Re: [whatwg] Fetch Objects and scripts/stylesheets

On Wed, Jul 23, 2014 at 1:07 AM, Ben Maurer <ben.maurer@gmail.com> wrote:
> To follow this up with a concrete suggestion:
>
> var myfetch = window.fetch('my.css', {'fetch-as': 'stylesheet'});
> myfetch.then(function(resp) {
>   document.body.appendChild(resp.body.asStyleSheet());
> });

If you have 'fetch-as' you need a strong guarantee that the response
can only be used for that purpose. How is that envisioned?

asStyleSheet() is an idea that was shot down before (back then it was
asHTML()) because it has the wrong layering semantics. We do not want
the Fetch layer to depend on the Layout layer.


> You can only call asStyleShet if fetch-as=stylesheet. Passing this
> parameter would cause the browser to do all the things it would do if it
> were fetching a stylesheet. For example, it would specify an accept header
> of text/css unless otherwise specified. It would request at the same
> priority as the browser requests other stylesheets (again, unless
> overridden with a yet-to-be-defined syntax). Rules around CORS and tainting
> would be identical to a normal stylesheet fetch (namely that you could
> call.asStyleSheet on a request to a different origin but it would have
> whatever restrictions the browser has on stylesheets from different
> origins). Links in the stylesheet would be interpreted relative to the URL
> used to load it, etc.

I have the feeling this should be a higher-level API as the browser
might also want to progressively parse the CSS and start speculatively
fetching the resources within.


-- 
http://annevankesteren.nl/

Received on Monday, 28 July 2014 07:55:17 UTC