Increase Browser Cache Lifetime of Static Assets in Shopware
If you’re analyzing your Shopware store with Google PageSpeed Insights or Lighthouse, you may receive a recommendation to increase the browser cache lifetime of static assets.
A short cache lifetime forces browsers to repeatedly download CSS, JavaScript, images, and fonts, leading to unnecessary network requests and slower page loads for returning visitors.
This guide explains how to configure long-term browser caching for static assets in Shopware using NGINX or Apache.
Problem
Your Shopware store may receive a performance warning similar to:
Increase the browser cache lifetime of static assets
This typically affects files such as:
- CSS
- JavaScript
- Images
- Fonts
Because these assets are cached for only a short period, browsers must download them again on future visits, increasing page load times.
Why It Happens
By default, your web server may not be configured to send long-lived cache headers for static assets.
Without appropriate Cache-Control and expiration headers, browsers cannot efficiently reuse previously downloaded resources.
Solution
Configure your web server to cache static assets for one year by sending long-lived Cache-Control headers.
NGINX Configuration
Edit your Shopware site’s NGINX configuration and add:
| 1 2 3 4 | location ~* \.(css|js|jpg|jpeg|png|gif|svg|webp|ico|woff|woff2|ttf|eot)$ { expires 365d; add_header Cache-Control "public, max-age=31536000, immutable"; } |
What these settings mean
- expires 365d – Sets the browser cache lifetime to one year.
- max-age=31536000 – Specifies the cache duration in seconds (31,536,000 seconds = one year).
- immutable – Informs the browser that the asset will not change during its cache lifetime, preventing unnecessary validation requests.
Apache Configuration
Add the following to your .htaccess file.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <IfModule mod_expires.c> ExpiresActive On ExpiresByType text/css "access plus 1 year" ExpiresByType application/javascript "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year" </IfModule> <IfModule mod_headers.c> <FilesMatch "\.(css|js|jpg|jpeg|png|gif|svg|woff|woff2)$"> Header set Cache-Control "public, max-age=31536000, immutable" </FilesMatch> </IfModule> |
Verify the Configuration
After updating your web server configuration:
- Reload or restart your web server.
- Open your Shopware storefront.
- Run Google PageSpeed Insights or Lighthouse again.
- Verify that the “Increase browser cache lifetime” recommendation has been reduced or resolved.
You can also inspect the response headers in your browser’s Developer Tools to confirm that the static assets include the expected Cache-Control and expiration headers.
Best Practice
Long cache lifetimes work best when your Shopware store uses versioned or hashed asset filenames. When an asset changes, its filename changes as well, allowing browsers to download the new version while efficiently caching unchanged assets.
Conclusion
Increasing the browser cache lifetime of static assets is a simple optimization that can improve your Shopware store’s performance, especially for returning visitors. By configuring your web server to cache CSS, JavaScript, images, and fonts for up to one year, you can reduce unnecessary requests and improve page speed scores.
Recent help desk articles
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.

