Compression and browser caching
Templ enables Gzip compression and sets browser-cache expiration headers automatically to reduce how much data visitors download. No setup is needed.
Gzip compression
Gzip compresses responses before sending them to the browser, which decompresses them for display. This reduces data transfer for files that can be compressed.
Browser caching
Expiration headers tell browsers how long they can reuse downloaded files instead of downloading them again. Browser caching stores files on the visitor's device; Templ Cache stores generated pages on the server.
Templ's default static-file headers look like this:
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Cache-Control: public
max-age is in seconds: 315360000 means 10 years and takes precedence over Expires. public also allows shared caches to store the file. When updating files, use cache busting so visitors download the new version.
Speed-test warnings about missing expiration headers can refer to files loaded from third-party servers, whose settings Templ doesn't control. Check which resource URLs the test flags before changing your site.