79531253

Date: 2025-03-24 13:53:45
Score: 0.5
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: kevin castaƱeda