Duplicate <link rel='preload'> and <script>
See original GitHub issueBug report
Describe the bug
When using Webpack’s magic comment (/* webpackChunkName: "balabala" */) to specify several modules bundling into one chunck, the output html contains duplicated <link rel='preload'> and <script> for the same chunck
To Reproduce
a simple respository to reproduce the bug:
https://github.com/xboy2012/nextjs-duplicate-dynamic-reproduce
In the respository I defined two modules, Module1 and Module2, using /* webpackChunkName: "allModules" */ to make them bundling into chunck allModules.
Just execute npm run dev, open http://localhost:3000/ in your browser.
Inspect the result HTML, then you’ll see duplicated <link rel='preload'> and <script> such as follows:
<!DOCTYPE html>
<html>
<head>
<meta charSet="utf-8" class="next-head"/>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" class="next-head"/>
<link rel="preload" href="/_next/static/development/pages/index.js?ts=1558408463129" as="script"/>
<link rel="preload" href="/_next/static/development/pages/_app.js?ts=1558408463129" as="script"/>
<link rel="preload" href="/_next/static/chunks/allModules.js?ts=1558408463129" as="script"/>
<link rel="preload" href="/_next/static/chunks/allModules.js?ts=1558408463129" as="script"/>
<link rel="preload" href="/_next/static/runtime/webpack.js?ts=1558408463129" as="script"/>
<link rel="preload" href="/_next/static/runtime/main.js?ts=1558408463129" as="script"/>
</head>
<body>
<div id="__next">
<div>
<div>This is module1</div>
<div>This is module2</div>
</div>
</div>
<script src="/_next/static/development/dll/dll_2011977376de5c4d4cfb.js?ts=1558408463129"></script>
<script id="__NEXT_DATA__" type="application/json">
{"dataManager":"[]","props":{"pageProps":{}},"page":"/","query":{},"buildId":"development","dynamicBuildId":false,"dynamicIds":["./components/Module1.js","./components/Module1.js"]}
</script>
<script async="" id="__NEXT_PAGE__/" src="/_next/static/development/pages/index.js?ts=1558408463129"></script>
<script async="" id="__NEXT_PAGE__/_app" src="/_next/static/development/pages/_app.js?ts=1558408463129"></script>
<script async="" src="/_next/static/chunks/allModules.js?ts=1558408463129"></script>
<script async="" src="/_next/static/chunks/allModules.js?ts=1558408463129"></script>
<script src="/_next/static/runtime/webpack.js?ts=1558408463129" async=""></script>
<script src="/_next/static/runtime/main.js?ts=1558408463129" async=""></script>
</body>
</html>
Obviously, allModules.js is preloaded and loaded twice.
Expected behavior
There should be no duplicated <link rel='preload'> and <script> for the same file.
Screenshots
See the above description
System information
- OS: macOS
- Browser Chrome
- Version of Next.js:
I wrote the repository to reproduce the bug using Next 8.x
In my company project I face the same bug using Next 7.x
So it’s likely all version have the bug
Additional context
Not yet.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:23 (8 by maintainers)

Top Related StackOverflow Question
@Timer , I am afraid the reproduction has been there on the index page of

next.jsofficial website.Please, is this a feature or a bug to be fixed? I bet it is a bug, or would you please point out a way to disable this feature?