W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2014

Re: [whatwg] Fetch Objects and scripts/stylesheets

From: Ian Hickson <ian@hixie.ch>
Date: Wed, 23 Jul 2014 00:33:22 +0000 (UTC)
To: Ben Maurer <ben.maurer@gmail.com>
Message-ID: <alpine.DEB.2.00.1407230028400.24594@ps20323.dreamhostps.com>
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>, William Chan (Dz) <willchan@chromium.org>
On Tue, 22 Jul 2014, Ben Maurer 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());
> });
> ...

Why not:

   var mystyle = E('link', { rel: 'stylesheet', href: 'my.css', whenneeded: true });
   document.body.appendChild(mystyle);
   var myfetch = mystyle.fetch;
   ...

...where "E()" is some mechanism to easily create new elements (we need 
one of those regardless), and "whenneeded" is some attribute that controls 
the load policy (and in this case, tells it to not load yet, since I 
presume that's what you're going to do next with the "myfetch" variable)?

("whenneeded" here is a placeholder. I don't expect to actually go with 
that. I just used it because it's what I had proposed the last time this 
came up.)

That seems like it'd be no more complicated, but would involve less new 
API surface (not to mention fewer new ways to shoot yourself in the foot, 
e.g. getting the 'fetch-as' value wrong), and wouldn't require us to come 
up with a way to enumerate all the kinds of fetch in an API.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 23 July 2014 00:33:51 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:21 UTC