Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preloading module doesn't work #2

Closed
anthonygore opened this issue Sep 25, 2017 · 7 comments
Closed

Preloading module doesn't work #2

anthonygore opened this issue Sep 25, 2017 · 7 comments

Comments

@anthonygore
Copy link
Owner

anthonygore commented Sep 25, 2017

Referring to the branch preload and to the file index.html:

https://github.com/anthonygore/vue-single-file-js-components/blob/preload/index.html

app.js imports SingleFileComponent.js. To speed the app up, I thought I could preload SingleFileComponent.js by adding this to index.html:

<link rel="preload" href="./SingleFileComponent.js" as="script">

But it doesn't work. I get this warning in Chome 61:

It also seems that Chrome loads SingleFileComponent.js again even though it should already be available.

@anthonygore anthonygore changed the title Preloading doesn't work Preloading module doesn't work Sep 25, 2017
@jakearchibald
Copy link

jakearchibald commented Sep 25, 2017

Could you reduce this some more? Or at least create an example of the bug that I can run by clicking a link?

For instance, here's a script loading another preloaded script, but the preloading works fine here, so there's something different between my example & yours. You'll probably discover what that is while you're making the reduced test.

This might help: https://css-tricks.com/reduced-test-cases/

@anthonygore
Copy link
Owner Author

Thanks for your patience.

Here's the live demo: http://preloadjsmodules.pancakeapps.com/

Here are the files for this reduced test case: https://github.com/anthonygore/preload-js-modules

@jakearchibald
Copy link

Cheers! Here's a further reduced case with a fix: https://module-load-preload.glitch.me/.

I was roughly in the right direction with https://twitter.com/jaffathecake/status/908561563212144643. You need the crossorigin attribute on both the script and the preload to put them into the same request mode.

@alexjoverm
Copy link

alexjoverm commented Sep 25, 2017

@jakearchibald thanks for your time on this!

Got some questions though:

  • Maybe I missed something, but what/where's exactly the fix? That reduced test case still shows that warning.
  • They are on the same origin, right? Since is a relative file path
  • What'd be the correct value? anonymous or use-credentials ?

@jakearchibald
Copy link

@alexjoverm

but what/where's exactly the fix?

The fix is putting crossorigin on both the module script and the preload. This is because modules are fetched without credentials by default. Although this looks set to change.

That reduced test case still shows that warning

You're talking about https://module-load-preload.glitch.me/ yeah? I don't see a warning in Chrome 61 or 63. Which version are you using?

What'd be the correct value?

The default value is fine (which is anonymous). However, this will send credentials for same origin. Yeah, it's weird. I brought it up on the spec, and it looks like it'll be changed.

@anthonygore
Copy link
Owner Author

Thanks, @jakearchibald. I'm on Chrome 61 and that fixed it perfectly for me.

@alexjoverm
Copy link

I was on Chrome 60. Maybe that's the reason.

Thanks a lot for the explanations btw, very helpful and clear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants