HTML Minifier
#7008
Replies: 1 comment
-
I just found out more information from the Discord channel crew. This example above, the hook runs on every request and isn't really good solution for that. Here are the new example until someone gave better solution: // hooks.server.js
import { minify } from 'html-minifier-terser'
import { dev, prerendering } from '$app/environment'
const minification_options = {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: true
}
export async function handle({ event, resolve }) {
let response = resolve(event)
if (!dev && prerendering) {
response = await resolve(event, {
transformPageChunk: ({ html }) => minify(html, minification_options)
})
}
return response
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm new to Svelte (coming from Vue) and looking into configurations and best practices before moving on to a real project.
SvelteKit seems to be an awesome choice for static generation.
So far I really like the development experience although some things take more time to search through the docs.
I did a little research and find another option transformPageChunk which I can use for manipulating
html
so I'm little confused.Is this example below safe to use for
html minify
and whether there are any differences from the official example? Does it actually have the same effect?Using this with
@sveltejs/adapter-static
and works fine:Beta Was this translation helpful? Give feedback.
All reactions