Browser Caching in Apache!

Is it necessary to add Cache-Control header along with Cache-request header?


<IfModule mod_expires.c>

ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"



Along with these codes in htaccess, is it necessary to add the below code:

1 Month for most static assets

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



Note: Site is using Cloudflare but no WP caching Plugin.

Kindly explain friends.

If you want a simpler life managing this, either control cache with apache and disable caching from cloudflare or don’t cache with apache and let cloudflare handle it.

Worst thing ever. Here’s why.

1 Like

Bro, that’s a sample code. Just for reference, I am looking for the context only.

Using Cloudflare? You can set here Browser caching easily.

Keep it 8 days minimum.
Cloudflare will add cache-control for each static files.

This is the Problem. The first run takes 4.02s DOM and the second one takes 2.32s only.
How to make the first run faster like the second one bro?
Using the above codes!

The Browser Cache Expiration is set to “Respect Existing Headers”.

If requirement is simple, then you should override it to 8 days. So, browser cache can work properly for static files.

All I need is same output between first run and the second run bro,

Impossible. Why Browser will show same output for repeat view?

First time, it loaded page from scratch, second time it would be quick, won’t take DNS Time like before, there will be cached response.

1 Like

But we declare as follows, just for an example take one jpeg image:

ExpiresByType image/jpg “A31536000”

Then what’s the use of this bro?

You shouldn’t keep both rules. Any one of them is sufficient.

Both are writing style. One is free to use whatever they want to use.

It’s writing style. For better understanding, you may check Apache Docs.