Cache static responses based on content-type to static files.

1.4.0 2022-02-08 20:18 UTC

This package is auto-updated.

Last update: 2023-01-11 12:17:37 UTC


Latest Version on Packagist Software License Buy us a tree Build Status Coverage Status Quality Score Total Downloads Made by SWIS


Via Composer

$ composer require swisnl/laravel-static-request-cache


Add the middleware to the end of your Http/Kernel.php middleware array.

protected $middleware = [

Add the following snippet into your .htaccess

# Rewrite to html cache if it exists and the request is for a static page
# (no url query params and only get requests)
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{DOCUMENT_ROOT}/static/html%{REQUEST_URI} -f
RewriteRule ^(.*)$  /static/html%{REQUEST_URI} [L]

RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{DOCUMENT_ROOT}/static/html%{REQUEST_URI}/index.html -f
RewriteRule ^(.*)$ /static/html%{REQUEST_URI}/index.html [L]


If you want to disable the cache for some reason (the content might be dynamic), you can use the StaticRequestCache singleton in the IoC:

public function __construct(StaticRequestCache $staticRequestCache)
    $this->staticRequestCache = $staticRequestCache;

Or use the Facade:


Please note that this package also checks for Cache-control headers and caches accordingly. You can change this behaviour in the config by editing non_cacheable_cache_control_values.

Clear the files

To clear all the files manually you can use an artisan command.

$ php artisan static-html-cache:clear

Change log

Please see CHANGELOG for more information on what has changed recently.


$ composer test


Please see CONTRIBUTING and CODE_OF_CONDUCT for details.


If you discover any security related issues, please email security@swis.nl instead of using the issue tracker.


Based on mscharl/laravel-static-html-cache. Added configuration for setting cacheable content-type and non-cacheable cache control values.


The MIT License (MIT). Please see License File for more information.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source

SWIS is a web agency from Leiden, the Netherlands. We love working with open source software.