Browser cache, CDN and connection hints
Three adjustments concern not the building of the page but its delivery: long-lived cache headers for static files, a CDN host in the asset addresses and early connection hints for third-party hosts. They take effect regardless of whether the page cache is running.
Browser cache rules in the .htaccess
- The “Browser cache (.htaccess)” card sits in the “Assets” panel, below the four switches.
- Look at the “Server” row: the rules only take effect on Apache and LiteSpeed.
- Check the “.htaccess writable” row. If it says “no”, writing fails with a message.
- Switch on “Write browser cache rules”. The block is written to the .htaccess in the WordPress directory.
- With “Write block” and “Remove block” the same block can be set again or taken out independently of the switch.
What the block contains
- Expires rules via mod_expires for CSS, JavaScript, PNG, JPEG, GIF, WebP, AVIF, SVG, icons and WOFF2, one year each
- A Cache-Control header via mod_headers for the same file types plus WOFF, TTF and OTF
- Compression via mod_deflate for HTML, text, CSS, JavaScript, JSON and SVG
Header set Cache-Control "public, max-age=31536000, immutable"Rewriting asset addresses to a CDN
- In the “Optimization” (in German: „Optimierung“) group, open the “CDN” item.
- Switch on “CDN delivery active”.
- Under “CDN base URL”, enter the address of the CDN host; it has to mirror the same paths as the site.
- The “Preview” card then shows an example of what a rewritten address looks like.
Only addresses of your own site are rewritten, and only static resources: CSS, JavaScript, images, fonts as well as some video and PDF files. This affects enqueued scripts and styles, attachment addresses and src, href and srcset in the content. No upload to the CDN takes place, the files have to be available there already.
dns-prefetch and preconnect
In the “Preload” panel (heading “Preload / Connections”) you can store hosts the browser should contact early: “dns-prefetch hosts” only resolves the name, “preconnect hosts” additionally establishes the connection. One host per line; the entries are hooked in via the WordPress filter for resource hints and de-duplicated in the process.