How to Make Your Website Faster: A Complete Guide
A faster website converts better, ranks higher and costs less to run. The good news: most sites leave enormous, easy performance wins on the table. This guide works through them from highest to lowest impact, with the config to actually apply each one.
1. Enable compression (gzip or Brotli)
Text assets — HTML, CSS, JS, JSON — compress by 70–90%. This is the single easiest win.
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
# Brotli (if the module is available) compresses even better
brotli on;
brotli_types text/css application/javascript application/json image/svg+xml;2. Set cache headers for static assets
Tell browsers to cache your CSS, JS, fonts and images for a long time. Combined with content hashing in filenames, this makes repeat visits nearly instant.
location ~* \.(css|js|woff2|jpg|jpeg|png|webp|svg|gif|ico)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}3. Use HTTP/2 or HTTP/3
HTTP/2 multiplexes many requests over one connection, eliminating the old need for asset concatenation hacks. HTTP/3 (over QUIC) improves things further on lossy networks. Both are a one-line change on a modern server:
server {
listen 443 ssl;
http2 on;
# ...
}4. Optimize images
Images are usually the heaviest part of a page. Three rules:
- Serve modern formats — WebP or AVIF — which are far smaller than JPEG/PNG.
- Resize to the actual displayed dimensions; don't ship a 4000px image into a 400px slot.
- Add
loading="lazy"to offscreen images and always setwidth/heightto prevent layout shift.
5. Put a CDN in front
A content delivery network caches your assets at edge locations close to users, cutting latency dramatically for a global audience and absorbing traffic spikes. For static and cacheable content, a CDN is one of the biggest wins you can buy.
6. Reduce and defer JavaScript
JavaScript is the most expensive resource a browser handles — it must be downloaded, parsed and executed. Ship less of it, split it into chunks, and defer non-critical scripts:
<script src="/js/analytics.js" defer></script>7. Tune the backend
- Cache database queries and rendered pages (Redis, Varnish, or a framework cache).
- Right-size your PHP-FPM / app worker pool so you don't queue requests.
- Add database indexes for slow queries — often the real bottleneck.
8. Measure, don't guess
Use Lighthouse, WebPageTest or your browser's Performance panel to find the actual bottleneck before optimizing. And keep an eye on server response time in production — a backend that's fast in dev can crawl under real traffic.