Skip to content

Commit

Permalink
Remove noscript
Browse files Browse the repository at this point in the history
  • Loading branch information
max-lt committed Feb 20, 2024
1 parent db96afe commit 4cd8b1f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ const mkdirAsync = promisify(mkdir);

const cache = new Map<string, string>();

function removeAll<K extends keyof HTMLElementTagNameMap>(nodes: NodeListOf<HTMLElementTagNameMap[K]>) {
const elements = Array.from(nodes);

for (const element of elements) {
element.remove();
}
}

const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideServerRendering(),
{
provide: BEFORE_APP_SERIALIZED,
useFactory: (document: Document) => () => {
const styles = Array.from(document.head.querySelectorAll('style'));

// Remove inlined "critical" styles
for (const style of styles) {
style.remove();
}
removeAll(document.head.querySelectorAll('style'));

// Remove noscript > link[rel="stylesheet"] elements
removeAll(document.head.querySelectorAll('noscript'));

// Remove style imports and replace them with inlined styles
const links = Array.from(document.head.querySelectorAll('link[rel="stylesheet"]'));
Expand Down

0 comments on commit 4cd8b1f

Please sign in to comment.