Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EiYuuChile's avatar

Problem with Cache-Control: no-cache in every file

Hello

I have a Laravel installation with inertia, vite and vue (using Laravel sail). After some weeks working, I noticed that all files from localhost, have Cache-Control: no-cache and every time I reload the page, every localhost file is again downloaded, not happen the same with files that come from outside like fonts from google or files from node_modules. Even if I make sail npm run build, the result is the same. I tried in many ways to solve the problem adding Cache-control in app.blade.php for example but without success. Any idea how I can solve this? I checked the laracast website that I understand use the same tech and every image or component is cached properly. Thanks

0 likes
4 replies
LaryAI's avatar
Level 58

One possible solution to this issue is to modify the caching headers in your Laravel application's configuration.

First, make sure that your Laravel application is using the correct environment configuration. You can check the .env file in the root directory of your Laravel project to ensure that the APP_ENV variable is set to the appropriate environment (e.g., local, production, etc.).

Next, open the config/cache.php file in your Laravel project. Look for the default configuration option and ensure that it is set to the desired cache driver (e.g., file, redis, etc.).

Once you have confirmed the cache driver, you can modify the caching headers by updating the config/cache.php file. Look for the stores configuration option and find the configuration for the cache driver you are using (e.g., file, redis, etc.). Within that configuration, you should see a headers option. Update the Cache-Control header value to the desired caching behavior. For example, you can set it to public to allow caching by both the browser and any intermediate caching proxies.

Here's an example of how the headers option might look in the config/cache.php file:

'stores' => [
    'file' => [
        'driver' => 'file',
        'path' => storage_path('framework/cache/data'),
        'headers' => [
            'Cache-Control' => 'public',
        ],
    ],
],

After making these changes, you may need to clear the cache for the changes to take effect. You can do this by running the following command in your terminal:

php artisan cache:clear

Please note that modifying caching headers can have implications on the performance and behavior of your application, so it's important to consider the caching strategy that best suits your needs.

Snapey's avatar

You sure you didn't add some middleware to disable http cache?

EiYuuChile's avatar

Not at all, even I back with git to the installation point and the problem is the same, That make me think can be a problem with Laravel Sail, but also looks like not. How I can check finding in files if I disable http cache? The files that come from node_modules or external like googlefonts are cached without problem. But images and js files created by vite from the vue componentes, all of them not.

Thanks so much for try to help

Please or to participate in this conversation.