W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2015

Re: JSON imports?

From: Glen Huang <curvedmark@gmail.com>
Date: Wed, 22 Apr 2015 11:10:52 +0800
Cc: Ilya Grigorik <igrigorik@google.com>, Matthew Robb <matthewwrobb@gmail.com>, public-webapps <public-webapps@w3.org>, Wilson Page <wilsonpage@me.com>
Message-Id: <F92FE39A-B982-4EC4-886E-7B7EB38C3423@gmail.com>
To: Elliott Sprehn <esprehn@chromium.org>
I just checked the html living standard, all it says about prefetch is 

> The prefetch keyword indicates that preemptively fetching and caching the specified resource is likely to be beneficial

This is pretty vague, and I sense the caching mechanism used by one vendor is not guaranteed to be the same for another.

<script type="application/json" src="foo.json"></script>

This is very easy to understand how it works, and much succinct comparing to prefetch and then refetch the same url (all you want is to load the json file asap, but you need to spread the logic in two places). Why not support it directly? The only downside I can see is that it should probably honor CORS headers, thus making it work a bit differently than a vanilla script, but that's something should be easy to grasp too.

> On Apr 19, 2015, at 5:15 PM, Elliott Sprehn <esprehn@chromium.org> wrote:
> 
> I'd hope with prefetch that we'd keep the data around in the memory cache waiting for the request.
> 
> On Apr 18, 2015 7:07 AM, "Glen Huang" <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
> Didn't know about this trick. Thanks.
> 
> But I guess you have to make sure the file being prefetched must have a long cache time set in the http header? Otherwise when it's fetched, the file is going to be downloaded again?
> 
> What if you don't have control over the json file's http header?
> 
>> On Apr 18, 2015, at 10:12 AM, Elliott Sprehn <esprehn@chromium.org <mailto:esprehn@chromium.org>> wrote:
>> 
>> <link rel=prefetch> does that for you.
>> 
>> On Apr 17, 2015 7:08 PM, "Glen Huang" <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
>> One benefit is that browsers can start downloading it asap, instead of waiting util the fetch code is executed (which could itself be in a separate file).
>> 
>>> On Apr 18, 2015, at 8:41 AM, Elliott Sprehn <esprehn@chromium.org <mailto:esprehn@chromium.org>> wrote:
>>> 
>>> 
>>> 
>>> On Fri, Apr 17, 2015 at 6:33 AM, Glen Huang <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
>>> Basic feature like this shouldn't rely on a custom solution. However, it does mean that if browsers implement this, it's easily polyfillable.
>>> 
>>> What does this get you over fetch() ? Imports run scripts and enforce ordering an deduplication. Importing JSON doesn't really make much sense.
>>> 
>>> 
>>>> On Apr 17, 2015, at 9:23 PM, Wilson Page <wilsonpage@me.com <mailto:wilsonpage@me.com>> wrote:
>>>> 
>>>> Sounds like something you could write yourself with a custom-elements. Yay extensible web :)
>>>> 
>>>> On Fri, Apr 17, 2015 at 1:32 PM, Matthew Robb <matthewwrobb@gmail.com <mailto:matthewwrobb@gmail.com>> wrote:
>>>> I like the idea of this. It reminds me of polymer's core-ajax component.
>>>> 
>>>> On Apr 16, 2015 11:39 PM, "Glen Huang" <curvedmark@gmail.com <mailto:curvedmark@gmail.com>> wrote:
>>>> Inspired by HTML imports, can we add JSON imports too?
>>>> 
>>>> ```html
>>>> <script type="application/json" src="foo.json" id="foo"></script>
>>>> <script type="application/json" id="bar">
>>>> { "foo": "bar" }
>>>> </script>
>>>> ```
>>>> 
>>>> ```js
>>>> document.getElementById("foo").json // or whatever
>>>> document.getElementById("bar").json
>>>> ```
>>>> 
>>>> 
>>> 
>>> 
>> 
> 
Received on Wednesday, 22 April 2015 03:11:31 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:31 UTC