next.js: Duplicate and
Bug 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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 23 (8 by maintainers)
@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?
Any thoughts? Please kindly introduce the design context/reason if this is intentional behavior. Otherwise, I guess this issue should be reopened.
We can still see this issue.
Steps to reproduce the behavior:
I pick up this issue and eventually get rid of those duplicate js files. The score on lighthouse raises immediately.
It is a feature from nextjs that
next/linkwill prefetch the content from the linked route by default. We have to setprefetchtofalseto disable this feature.I have to say, I am disappointed at no one from nextjs give a word on these github issues as an official reply.
I am still facing the same issue in the latest version of next. Can we at least re-open this issue?
@vinit-m this has been fixed in the latest stable Next release. You’re on an old version!