The Svelte 5 SSG Migration #1
@@ -20,23 +20,23 @@ const DIST = path.join(ROOT, 'dist');
|
||||
* Critters leaves rel="stylesheet" on swap links; change to rel="preload" as="style"
|
||||
* so the full CSS loads async and only applies on load (non-blocking).
|
||||
*/
|
||||
function postProcessSwapLinks(html) {
|
||||
return html.replace(/<link\s+([^>]*)>/gi, (full, attrs) => {
|
||||
if (
|
||||
!/rel="stylesheet"/i.test(attrs) ||
|
||||
!/onload="this\.rel='stylesheet'"/i.test(attrs)
|
||||
) {
|
||||
return full;
|
||||
}
|
||||
const fixed = attrs
|
||||
.replace(/\brel="stylesheet"\s*/i, 'rel="preload" as="style" ')
|
||||
.replace(
|
||||
/\bonload="this\.rel='stylesheet'"/i,
|
||||
'onload="this.onload=null;this.rel=\'stylesheet\'"',
|
||||
);
|
||||
return `<link ${fixed}>`;
|
||||
});
|
||||
}
|
||||
// function postProcessSwapLinks(html) {
|
||||
// return html.replace(/<link\s+([^>]*)>/gi, (full, attrs) => {
|
||||
// if (
|
||||
// !/rel="stylesheet"/i.test(attrs) ||
|
||||
// !/onload="this\.rel='stylesheet'"/i.test(attrs)
|
||||
// ) {
|
||||
// return full;
|
||||
// }
|
||||
// const fixed = attrs
|
||||
// .replace(/\brel="stylesheet"\s*/i, 'rel="preload" as="style" ')
|
||||
// .replace(
|
||||
// /\bonload="this\.rel='stylesheet'"/i,
|
||||
// 'onload="this.onload=null;this.rel=\'stylesheet\'"',
|
||||
// );
|
||||
// return `<link ${fixed}>`;
|
||||
// });
|
||||
// }
|
||||
|
||||
async function main() {
|
||||
if (!fs.existsSync(DIST)) {
|
||||
|
||||
Reference in New Issue
Block a user