web icon indicating copy to clipboard operation
web copied to clipboard

Hash preload and prefetch link assets with Rollup Plugin HTML

Open joppekroon opened this issue 3 years ago • 0 comments

When trying to improve the performance of a site, you can add a link element with the rel attribute set to preload, prefetch. Unfortunately, this does not work when using rollup-plugin-html, as it will not recognize these links as assets it should hash.

Currently

<link rel="preload" href="foobar.css" as="style">
...
<link rel="stylesheet" href="foobar.css">

becomes:

<link rel="preload" href="foobar.css" as="style">
...
<link rel="stylesheet" href="foobar-abcdefgh.css">

but should become:

<link rel="preload" href="foobar-abcdefgh.css" as="style">
...
<link rel="stylesheet" href="foobar-abcdefgh.css">

You could look for style or image in the as attribute to decide whether to apply the hash.

joppekroon avatar Jun 08 '22 14:06 joppekroon