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

perf: defer application main JS chunks #3619

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/serious-trainers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@commercetools-frontend/mc-html-template": patch
"@commercetools-frontend/mc-scripts": patch
---

Use `defer` when loading main application JavaScript chunks.
6 changes: 3 additions & 3 deletions packages/mc-html-template/html-docs/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
href="__CDN_URL__favicon_144x144px.png"
/>

<!-- Main application chunks -->
__APPLICATION_SCRIPT_IMPORTS__

<!-- Fonts -->
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Open+Sans:ital,wght@0,300;0,400;0,700;1,400;1,700&display=swap"
Expand Down Expand Up @@ -167,8 +170,5 @@

<!-- Application globals -->
__APPLICATION_ENVIRONMENT__

<!-- Main application chunks -->
__APPLICATION_SCRIPT_IMPORTS__
</body>
</html>
2 changes: 1 addition & 1 deletion packages/mc-html-template/src/webpack-html-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function webpackHtmlTemplate(templateParams: TemplateParameter) {
`<link href="__CDN_URL__${chunkPath}" rel='stylesheet' type='text/css'>`
);
const scriptImports = scriptChunks.map(
(chunkPath) => `<script src="__CDN_URL__${chunkPath}"></script>`
(chunkPath) => `<script src="__CDN_URL__${chunkPath}" defer></script>`
);

return generateTemplate({ cssImports, scriptImports });
Expand Down
4 changes: 3 additions & 1 deletion packages/mc-scripts/src/commands/build-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ async function run() {
const html = generateTemplate({
// Define the module entry point (path relative from the `/public` folder).
// NOTE: that this is different from the development configuration.
scriptImports: [`<script type="module" src="/${appEntryPoint}"></script>`],
scriptImports: [
`<script type="module" src="/${appEntryPoint}" defer></script>`,
],
});
// Write `index.html` (template) into the `/public` folder.
fs.writeFileSync(paths.appIndexHtml, html, { encoding: 'utf8' });
Expand Down
2 changes: 1 addition & 1 deletion packages/mc-scripts/src/commands/start-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function run() {
// Define the module entry point (path relative to the `/public` folder).
// NOTE: that this is different from the production configuration.
scriptImports: [
`<script type="module" src="/../${appEntryPoint}"></script>`,
`<script type="module" src="/../${appEntryPoint}" defer></script>`,
],
});
// Write `index.html` (template) into the `/public` folder.
Expand Down