HTML import not deduping
Asked Answered
S

1

1

So the first fact section in this HTML import article states that html imports know better than to request (and execute - if javascript) resources multiple times.

This works within the framework of HTML imports but doesn't work for other type of imports (as in javascript). In this network view of the devtools you can see Polymer.html being loaded first from javascript (d3.js) then again from HTML imports (my-app.html) which I wasn't expecting.

enter image description here

Is there a way to explicitly tell HTML imports that a resource has already been loaded (as in from javascript in this case)?

Shank answered 11/3, 2015 at 17:30 Comment(2)
Since Polymer.html only consumes 700 bytes and is done in like 5ms I wouldn't be that interessted in putting effor to reduce the amount of loads. The big thing is polymer.js and it's loaded once and than read from cache. Seems ok for me...Chlorobenzene
@RobertHahn the problem isn't the load, but the script is executed twice.Shank
S
0

If I understand this correctly, you are having script file load multiple times because they are called in multiple elements. Please correct me if this is not right.

I do see that the HTML file is what is being parsed twice but the script inside it is actually pulled from cache (on the second reference). If you don't want the HTML file to be parsed again, you'll need to setup caching for the HTML at the server or Service Worker level.

Sheol answered 12/3, 2015 at 9:51 Comment(6)
The script file load multiple times from the same element. That element is requested once through xhr, once through html import.Shank
unrelated - I noticed your disabled cache was on as well. Does toggling that change anything?Sheol
Even with caching on, polymer.js will run twiceShank
can you send me a link to look at? I apologize but looking at your console I see it only loading once.Sheol
sure thing, have a look at this commitShank
what does d3.html() do? It looks like you might be loading things over XHR and Imports, but I wouldn't imagine imports would dedupe if you specifically request a resource over XHR as well.Moldau

© 2022 - 2024 — McMap. All rights reserved.