I've managed to compress HTML files using nitro plugin and h3-compression library.
import { useCompression } from "h3-compression";
export default defineNitroPlugin(nitroApp => {
nitroApp.hooks.hook("render:response", async (response, { event }) => {
try {
const contentType = response.headers?.["content-type"];
if (contentType && contentType?.includes("text/html")) {
await useCompression(event, response);
}
} catch (e) {
logger.error("Compressing error:", e);
}
});
});
However, this add around 100ms of loading time per file, while achieving 60% reduction on html size.