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

Implement/document <link rel="prefetch" for fonts and for .js files generated by code splitting feature #9929

Open
stargazer33 opened this issue Aug 26, 2024 · 3 comments

Comments

@stargazer33
Copy link

stargazer33 commented Aug 26, 2024

🙋 feature request

Parcel can generate files not listed under HTML <head>. Examples:

  1. Fonts, like dist/ex/bootstrap-icons.3536be6d.woff2

  2. Files created by code splitting feature: In JS code I do typesensePromise = import('typesense')
    and Parcel creates dist/ex/Typesense.dd42cc95.js 167 KB

I would like to see Parcel-generated prefetch links:
<link rel="prefetch" src="generated filename">
for such files.

If this already possible with Parcel - I would like to read documentation about this.
Can not find it in current documentation

🤔 Expected Behavior

Parcel generates prefetch links:
<link rel="prefetch" src="generated filename">
for icon fonts and JS files created by code splitting feature.

😯 Current Behavior

There are no prefetch links. Documentation does not mention this.

🔦 Context

This should improve page load speed

@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@Vresod
Copy link

Vresod commented Oct 28, 2024

I agree with this! though Parcel's development seems to be stunted right now

@solonovamax
Copy link

solonovamax commented Dec 25, 2024

This would be extremely useful. As a more concrete example:

Let's say you have some html:

<html lang="en">
<head>
    <link href="/src/assets/my-css.css"/>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

and then src/assets/my-css.css:

@font-face {
    font-family: "Fira Sans";
    src:         local("Fira Sans Regular"),
                 url("/src/fonts/FiraSans-Regular.woff2") format("woff2"),
                 url("/src/fonts/FiraSans-Regular.woff") format("woff"),
                 url("/src/fonts/FiraSans-Regular.ttf") format("truetype");
    font-weight: 400;
    font-style:  normal;
}

body {
    font-family: "Fira Sans";
}

In generated html you will get something similar to

<html lang="en">
<head>
    <link href="/my-css.210620cd.css"/>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

and the following css:

@font-face {
    font-family: "Fira Sans";
    src:         local("Fira Sans Regular"),
                 url("FiraSans-Regular.c0cf7a86.woff2") format("woff2"),
                 url("FiraSans-Regular.06734e01.woff") format("woff"),
                 url("FiraSans-Regular.6dac1c26.ttf") format("truetype");
    font-weight: 400;
    font-style:  normal;
}

body {
    font-family: "Fira Sans";
}

This causes the following request tree to be made by the browser when requesting that page:

index.html
\- my-css.210620cd.css
   \- FiraSans-Regular.c0cf7a86.woff2

The problem here, is that the browser must make a request for index.html, parse the html, make a request for my-css.210620.css, parse the css, and then make a request for FiraSans-Regular.c0cf7a86.woff2.

However, if parcel were able to generate the following html:

<html lang="en">
<head>
    <link href="/my-css.210620cd.css"/>
    <link rel="preload" href="/FiraSans-Regular.c0cf7a86.woff2" as="font">
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

This would cause both my-css.210620cd.css and FiraSans-Regular.c0cf7a86.woff2 to be fetched simultaneously, instead resulting in the following requests:

index.html
|- my-css.210620cd.css
\- FiraSans-Regular.c0cf7a86.woff2

@solonovamax
Copy link

Also, @stargazer33, I believe you meant rel="preload" rather than rel="prefetch".
See: https://developer.chrome.com/blog/link-rel-preload/

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

4 participants
@stargazer33 @Vresod @solonovamax and others