Doubt about cached files

Asked

Viewed 173 times

0

Guys I’m putting together a system in php, and I’m creating the material design that will be used in the system. I created 2 files, 1º Materia.js and 2º Material.css.

Good in these files I will put all the CSS and JS. I will call the file on the login screen and the logged in page.

My question is every time the logged in page is loaded the Bowser will download the files or will load it from the cache?

This will make the system heavy?

I’m following the way Materializer works.

1 answer

2


This depends on whether you want the server to cache the resources or not, this can be seen in one of the parameters of the requested server response headers, in the case of facebook is:

Cache-Control: "private, no-cache, no-store, must-revalidate"

This means don’t cache anything, it always renews, and it’s private (in case you have something cached, it’s just for me). Here and here are these paramenters best explained.

To set up your server cache in php you can do:

header("Cache-Control: private, no-cache, must-revalidate");

Or in html you can also exs:

<meta http-equiv="Cache-control" content="public">
<meta http-equiv="Cache-control" content="private">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">

Or htaccess ex:

<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>

In this case, this htaccess serveria for your case caches the resources with these extensions. But note that this could be set in php as well

An aspect not directly related to the question, but it has to do with performance, it is also important to do gzip resources, can in the .htaccess do:

<IfModule mod_deflate.c>
    <FilesMatch "\.(html|php|txt|xml|js|css)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>

To answer your question, you can control it on the server and configure it with your preferences, here another reference.

  • hum, so it’s possible to cache JS and CSS, good. You could show me how to make the system store JS and CSS in public cache and PNG I don’t want to save. I wanted to do this via htaccess.

  • You have the example for this in the reply, I edited htaccess @Hugoborges

  • OK thank you very much

  • 1

    @Hugoborges, an alert... If you’re working on the site and you don’t see anything change that’s why, because of this cache

Browser other questions tagged

You are not signed in. Login or sign up in order to post.