Re: [whatwg] Fetch Objects and scripts/stylesheets

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