- From: Ryosuke Niwa <rniwa@apple.com>
- Date: Thu, 11 Sep 2014 16:52:03 -0700
- To: Ian Hickson <ian@hixie.ch>
- Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>, "William Chan (???)" <willchan@chromium.org>, Ben Maurer <ben.maurer@gmail.com>
On Jul 22, 2014, at 5:33 PM, Ian Hickson <ian@hixie.ch> wrote: > 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. That seems like a reasonable approach to the problem at hand. It still poses a question as to how we can add a similar API for other types of resources (videos, images, etc…). Any thoughts on that? - R. Niwa
Received on Thursday, 11 September 2014 23:52:28 UTC