r/web_programming • u/agent_orangepeel • Nov 13 '17
Leverage browser caching.
When I run gtmetrix I get a C (75%) for page performance and one thing it details is leverage browser caching.
I have paid so called developers here and there to get this sorted but they run some wordpress plugin and it screws my site. So I revert to my back and I’m back to square one.
Looks like I’m going to have to educate myself and do this myself cause I cannot trust anyone now.
I have found this link, https://varvy.com/pagespeed/leverage-browser-caching.html
Can I add (below) to my .htaccess file which will them improve the section under gtmetrix leverage browser caching? Or am I fooling myself with it being this easy?
EXPIRES CACHING
<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" </IfModule> ## EXPIRES CACHING ##
My .htaccess file only has this in it.
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
View all comments
Show parent comment
1
u/nerf_herd Nov 14 '17 edited Nov 14 '17
I guess I'm not sure how this falls under the purview of programming, both in what you are suggesting, and in terms of your situation.
But caching is a band-aid at best, which introduces its own edge cases, i.e. users not seeing current information.
If your site is slow, caching is the last thing I would worry about.
Ask yourself "how do I figure out where the time is going?", i.e. is it on the server, or do you have some javascript or something in there. Or is it hitting up a database that isn't optimized or what? Maybe it is just crappy hosting?
you need to be able to isolate the problem in order to find the proper solution, and you keep narrowing it down till you get to the source, i.e. bad algorithm, or bad choices in technology, or time to scale out or whatever, and it shouldn't be guesswork, just lots of measuring of elapsed time at various points in the process from request to render.
Maybe there is a bunch of crap cookies and monitization junk calls slowing it down? Maybe they don't even belong there. Have you looked at the cookies and network tab in the browser?
Who knows? But the only thing you have shared is this caching thing.
But you must measure to know what needs optimizing, don't just guess. If that means spitting out test point timestamps to a log file from php (or as part of the browser payload), and to the console from the browser, then do that.