Skip to content

Commit ea5f71e

Browse files
developitprateekbh
authored andcommitted
Use nomodule to conditionally load fetch+promise (#833)
1 parent 7802729 commit ea5f71e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/cli/lib/resources/template.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
<%= htmlWebpackPlugin.options.ssr() %>
2424
<% if (webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/)).length > 0) { %>
2525
<% /* Fix for safari < 11 nomodule bug. TODO: Do the following only for safari. */ %>
26-
<script>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
26+
<script nomodule>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
2727
<script crossorigin="anonymous" src="<%= htmlWebpackPlugin.files.publicPath %><%= webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/))[0].name %>" type="module"></script>
2828
<%
2929
/*Fetch and Promise polyfills are not needed for browsers that support type=module
3030
Please re-evaluate below line if adding more polyfills.*/
3131
%>
32-
<script nomodule>window.fetch||document.write('<script src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"><\/script>')</script>
32+
<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
3333
<script nomodule defer src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
3434
<% } else { %>
3535
<script <%= htmlWebpackPlugin.options.scriptLoading %> src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
36-
<script>window.fetch||document.write('<script src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"><\/script>')</script>
36+
<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
3737
<% } %>
3838
</body>
3939
</html>

0 commit comments

Comments
 (0)