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

webpackPreload not working at all #2457

Closed
webpack-bot opened this issue Aug 21, 2018 · 3 comments
Closed

webpackPreload not working at all #2457

webpack-bot opened this issue Aug 21, 2018 · 3 comments

Comments

@webpack-bot
Copy link

What is the current behavior?
I am experiencing issues while using webpackPreload.
No script with rel="preload" is added to the <head>.

Steps to reproduce

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'none',
  plugins: [
      new HtmlWebpackPlugin({template: './src/index.html'}),
  ]
};
export function divide(a, b) {
    return a / b;
}
document.addEventListener("DOMContentLoaded", () => {
    const button = document.querySelector('#divideButton');
    button.addEventListener('click', () => {
        import(
            `./utilities/divide`
            /* webpackPreload: true */
            /* webpackChunkName: "utilities" */
            )
            .then(divideModule => {
                console.log(divideModule.divide(6, 3)); // 2
            })
    });
});
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <button id="divideButton">Click</button>
    </body>
</html>

I am using webpack@4.16.5.

What is the expected behavior?
I expect the <link rel="preload" as="script" href="utilities.js"> to be added.

Other relevant information:
webpack version: 4.16.5
Node.js version: 8.11.3
Operating System: Ubuntu 18.04


This issue was moved from webpack/webpack#7920 by @sokra. Original issue was by @mwanago.

@sokra The docs do not mention the need to use html-plugin for preload.
Prefetch is working without problems.
https://webpack.js.org/guides/code-splitting/#prefetching-preloading-modules

That's true. It's mentioned here: https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c in the FAQ

Please send a PR to the docs adding it.

@EugeneHlushko
Copy link
Member

Hi @mwanago , you will work on this?

@EugeneHlushko
Copy link
Member

Closing this issue, PR: webpack/webpack/pull/7444 had "fixed" the behaviour mentioned in caveat when prefetch/preload did not work for entry chunk.

And, entryPrefetchFunction wasn't merged, it was changed so there is nothing to document here.

@haight6716
Copy link

haight6716 commented Feb 19, 2021

Just ran into this problem. Prefetch works, preload does not.

    "webpack": "4.28.3",

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