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

Prefetching/Preloading modules #79

Closed
ram-you opened this issue Aug 11, 2018 · 4 comments
Closed

Prefetching/Preloading modules #79

ram-you opened this issue Aug 11, 2018 · 4 comments
Assignees
Labels

Comments

@ram-you
Copy link

ram-you commented Aug 11, 2018

Hi, can you please implement Prefetching/Preloading modules to have something like this in the header tag :
<link rel="prefetch" href="login-modal-chunk.js">
?

Thank you.

@mubaidr mubaidr self-assigned this Aug 11, 2018
@mubaidr mubaidr added the review label Aug 11, 2018
@mubaidr
Copy link
Owner

mubaidr commented Aug 11, 2018

This should be working by default. But I will review and post here the results.

@mubaidr
Copy link
Owner

mubaidr commented Aug 13, 2018

Confirmed. There are two use cases;

  • If the asset you want to prefetch is an static asset, place it in static directory and link it in index.html
<link rel="prefetch" href="./static/login-modal-chunk.js">
  • If asset is dynamic (means requires compilation sass, js etc) then:
    update your import:
import("LoginModal")

to:

import(/* webpackPrefetch: true */ "LoginModal")

^ it will prefetch the asset.

I Hope this helps.

@ram-you
Copy link
Author

ram-you commented Aug 13, 2018

Thanks a lot.
Your second solution works fine.

new ScriptExtHtmlWebpackPlugin({
      async: /\.js$/,      
      prefetch: {
        test: /\.js$/,
        chunks: 'async'
      }
})

@mubaidr
Copy link
Owner

mubaidr commented Aug 13, 2018

Great! 👍

@mubaidr mubaidr closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants