web
web copied to clipboard
Hash preload and prefetch link assets with Rollup Plugin HTML
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.