How do I speed up my website? Images, JavaScript, caching and prefetching
To speed up a website, measure Core Web Vitals with real visitor data first, then fix images, JavaScript, plugins and caching in that order.


Measure what is slow with real visitor data first, then start with the biggest items. On most sites the order runs like this. Resize images and convert them to WebP or AVIF, remove JavaScript and plugins you do not need, keep pages prepared in advance and set up caching properly. The last step, loading a page in the background when someone hovers over a link, is the finishing touch.
How should I measure speed?
Google looks at three measurements. According to web.dev, the largest piece of content (LCP) should load within 2.5 seconds of the page starting to load, the response to clicks and taps (INP) should be 200 milliseconds or less, and layout shift (CLS) should be 0.1 or less. These thresholds are checked separately for mobile and desktop, at the 75th percentile of page loads.
Tools like Lighthouse run one scenario on one device. What real visitors experience is field data, measured across different devices, networks and behaviours. web.dev recommends setting your priorities from field data and using lab data for debugging. Google's page experience documentation says Core Web Vitals are used by its ranking systems, but also that a good score does not guarantee a top position. Speed matters to the visitor before it matters to a search engine.
How do I make images smaller?
Fix the size first. There is no point uploading a 3000 pixel file for an image that takes up 600 pixels on screen. On a beauty centre website we reviewed, four PNG images shown at about 300 pixels were each between 6 and 9 MB, and that is why the home page weighed about 30 MB. High-density screens need somewhat more pixels, but as web.dev explains, a 100 by 100 pixel area on a 2x screen needs four times the pixels. Produce what is needed and no more. Then look at the format. WebP and AVIF generally compress better than JPEG and PNG and work in all modern browsers. Since version 6.5 WordPress supports uploading AVIF, but the server's image library has to support it too. In Next.js the next/image component resizes images and converts them to modern formats such as WebP for you.
The largest image on the page is a separate matter. web.dev's LCP guide says never to lazy-load that image. It should be in the initial HTML, it should get high priority, and that priority should go to only one or two images. If a setting that lazy-loads every image also covers the first one, LCP gets worse.
How do I cut JavaScript, plugins and queries on the back end?
The main reason INP stays high is often JavaScript. Scripts that keep the main thread busy for a long time delay the response to a click. There are techniques such as tree shaking to drop unused code from a bundle, but a developer does that. We do this work, starting from measurement, as part of site speed optimization.
On WordPress, much of the work is in plugins. WordPress's own optimization guide names deleting unnecessary plugins as the easiest first step, and tells you to measure which one slows the site by disabling them one at a time. For queries that pile up on the back end, the same guide lists limiting stored post revisions, converting tables to InnoDB and setting up a persistent object cache. How plugins and queries slow a site is covered separately in why is my WordPress site slow.
What do prepared pages and caching give me?
The fastest answer is the one that is never calculated. On WordPress, caching plugins save pages as static files, so the server does not rebuild the page for every visitor. According to the guide this can improve performance several hundred times over for fairly static pages. A content delivery network can also take images and scripts off your server.
In Next.js a page is produced ahead of time at build, and with incremental static regeneration it updates without rebuilding the whole site. If only part of a page changes often, you do not need to make all of it dynamic. The Next.js caching documentation shows it this way. The navigation bar and product information arrive ready in a static shell, and parts such as the cart and recommended products stream in afterwards. On an ecommerce page the price can arrive dynamically while the product description and specifications stay static. The page appears at once and the changing part fills in behind it.
How does prefetching work?
Prefetching means fetching the destination page in the background before the visitor clicks a link. The Next.js Link component loads the route ahead of time when the link enters the viewport. For a static route it fetches the whole page, and for a dynamic route only part of it. In very long lists of links, where that adds needless load, you can prefetch only on hover.
Since version 6.8 WordPress core has a similar feature. Speculative loading by default fetches the page's server response as the visitor starts to click a link. When the WordPress team announced it, only Chrome, Edge and Opera supported it, and browsers without support ignore it. Chrome's documentation describes levels you can tune from hover to eager, and warns that over-speculation wastes bandwidth and adds load on the origin server. So prefetching helps, but it does not fix the underlying problem of a slow page.