devpunks / snuggsi

snuggsi ツ - Easy Custom Elements in ~1kB
https://snuggsi.com
MIT License
398 stars 17 forks source link

Asynchronous Import Loading #75

Closed snuggs closed 7 years ago

snuggs commented 7 years ago

@brandondees noticed there was an async attribute on HTMLLInkElement. What would we use this for? Should all imports be asynced? /cc @RobertChristopher.

https://w3c.github.io/webcomponents/spec/imports/#link-type-import

snuggs commented 7 years ago

I think they are async by default. https://bugs.chromium.org/p/chromium/issues/detail?id=523952

tmornini commented 7 years ago

I think they are async by default

This comment on that thread appears to disagree.

icyc9 commented 7 years ago

There are definitely contexts in which async imports are not appropriate due to dependency resolutions.

snuggs commented 7 years ago

@brandondees probably want to know about this comment here. Looking bleek for imports. You see this is why we can't have nice things:

brandondees commented 7 years ago

async and defer have distinct behavior. DEFER means execute in order, but loading can happen concurrently. defer is pretty much always a safe option that can potentially yield performance improvement. async is not a safe universal option and shouldn't be used without consideration. according to the MDN doc i read, I believe... async is a promise to the user agent to not do anything in the script that will depend on the rest of the document state being ready. e.g. it's a "go ahead and knock this work out as early as possible because it doesn't depend on anything like dom or other scripts, but other things can depend on it"

snuggs commented 7 years ago

@brandondees ok so does that mean <script async src=https://snuggsi.es> would be standard? I've run into this race condition between the lib not being loaded and being loaded when testing it. I couldn't figure out the proper convention so just removed them all.

brandondees commented 7 years ago

no it means <script defer src=https://snuggsi.es> should be standard and adding async should always be at the discretion of the page author

brandondees commented 7 years ago

defer means "go ahead and keep parsing the document while this thing loads, but if you come to another script, put it in line after this one"

snuggs commented 7 years ago

THAT is why snuggsi wasn't loading with an inline Element definition. The lib would load way after the inline definition. Thanks @brandondees.

I think we can close this then yes?

icyc9 commented 7 years ago

Yep, I'd say things are cleared up. @snuggs

snuggs commented 7 years ago

👍