Google Pagespeed Insights Says Browser Cache isn't Being Leveraged
If you feel the issue is an EasyEngine core specific issue, please attach the output of the following commands.
System Information
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic EE 4.0.0-rc.1 +-------------------+----------------------------------------------------------+ | OS | Linux 4.15.0-23-generic #25-Ubuntu SMP Wed May 23 18:02: | | | 16 UTC 2018 x86_64 | | Shell | /bin/bash | | PHP binary | /usr/bin/php7.2 | | PHP version | 7.2.11-3+ubuntu18.04.1+deb.sury.org+1 | | php.ini used | /etc/php/7.2/cli/php.ini | | EE root dir | phar://ee.phar | | EE vendor dir | phar://ee.phar/vendor | | EE phar path | /root | | EE packages dir | | | EE global config | /opt/easyengine/config/config.yml | | EE project config | | | EE version | 4.0.0-rc.1 | +-------------------+----------------------------------------------------------+ wp: command not found
I was asked to submit a new issue for this as instructed here
- https://github.com/EasyEngine/easyengine/issues/1272#issuecomment-435753043
I created a test website with EE4 RC1 2 or 3 days ago and wanted to know if I needed any extra caching plugins to compliment what I had already setup.
My setup command was. . .
- ee site create shaylahleigh.com --type=wp --cache --admin-user=user--admin-pass=pass --ssl=le
But when I go to Google Pagespeed Insights, I am told that I am not leveraging Browser Cache and am told the following files are being ignored in the caching process. . .
- https://shaylahleigh.com/…ntyseventeen/assets/js/global.js?ver=1.0 (24 hours)
- https://shaylahleigh.com/…n/assets/js/jquery.scrollTo.js?ver=2.1.2 (24 hours)
- https://shaylahleigh.com/…assets/js/skip-link-focus-fix.js?ver=1.0 (24 hours)
- https://shaylahleigh.com/…emes/twentyseventeen/style.css?ver=4.9.8 (24 hours)
- https://shaylahleigh.com/…s/jquery/jquery-migrate.min.js?ver=1.4.1 (24 hours)
- https://shaylahleigh.com/…-includes/js/jquery/jquery.js?ver=1.12.4 (24 hours)
- https://shaylahleigh.com/…wp-includes/js/wp-embed.min.js?ver=4.9.8 (24 hours)
- https://shaylahleigh.com/…des/js/wp-emoji-release.min.js?ver=4.9.8 (24 hours)
So I was curious if I needed to use a caching program like WP Rocket, W3 Total Cache, Super Cache or any other plugin to properly cache the files Google is complaining about with the default 2018 WP theme
If you remove query strings from your js and css files you should get rid of this issue pretty easily. You can use a free plugin like Machete (which has an option to do this, but also quite a few other options to remove unnecessary features from your header). There's also other free plugins called query strings remover, and Remove Query Strings From Static Resources. The latter two don't need you to even tick any boxes to enable the feature, just activate the plugin and flush your cache.
Then your js and css files will be cached like your other files, according to your settings. I've found that removing query strings is a big part in drastically decreasing load times on my website, down to ~1.4 seconds now under heavy load. If I leave query strings in, my load times are around 1.5 seconds longer. This is especially important if you use a 3rd party theme / plugins.
It would be cool if EE installed and enabled one of these plugins when you first set up a wp website with the --cache flag imo.
If you remove query strings from your js and css files you should get rid of this issue pretty easily. You can use a free plugin like Machete (which has an option to do this, but also quite a few other options to remove unnecessary features from your header). There's also other free plugins called query strings remover, and Remove Query Strings From Static Resources. The latter two don't need you to even tick any boxes to enable the feature, just activate the plugin and flush your cache.
Then your js and css files will be cached like your other files, according to your settings. I've found that removing query strings is a big part in drastically decreasing load times on my website, down to ~1.4 seconds now under heavy load. If I leave query strings in, my load times are around 1.5 seconds longer. This is especially important if you use a 3rd party theme / plugins.
It would be cool if EE installed and enabled one of these plugins when you first set up a wp website with the --cache flag imo.
I am a fan of Autoptimize and it has a feature with the description. . .
- Removing query strings (or more specifically the ver parameter) will not improve load time, but might improve performance scores.
I will give that a shot. And if it fails then I'll try the Machete plugin that you suggested.
I tried Machete and Autoptimize, they can remove the query strings from the static resources, but pagespeed keeps complaining about leveraging browser cache.
There's a year and half old post about it on the rtcamp forum about it: https://community.easyengine.io/t/how-do-i-enable-browser-caching/8440
I noticed there is also a custom folder with a user.conf file for the sites created: /var/lib/docker/volumes/examplecom_config_nginx/_data/custom/user.conf
I tried inserting those rules to leverage the browser cache but the user.conf doesn't seem to be included in the nginx.conf file.
So I wonder if someone could point me on how to include it.
Also: would not be better to have it on by default?
I tried inserting those rules to leverage the browser cache but the user.conf doesn't seem to be included in the nginx.conf file.
@tacensi Did you try ee site restart/reload example.com after doing it?
@kirtangajjar
Yes indeed.
Here is the headers for one of the scripts googlespeed is complaining about:
curl -sD - -o /dev/null https://tacensi.com/wp-includes/js/wp-emoji-release.min.js
HTTP/2 200
server: nginx
date: Thu, 08 Nov 2018 17:10:53 GMT
content-type: application/javascript
content-length: 12026
last-modified: Tue, 06 Nov 2018 18:16:52 GMT
vary: Accept-Encoding
etag: "5be1da94-2efa"
expires: Fri, 09 Nov 2018 17:10:53 GMT
cache-control: max-age=86400
cache-control: public, must-revalidate
accept-ranges: bytes
Is there a way to check if it is getting loaded?
@kirtangajjar
I took a time to look at it a little more. Actually, user.conf is being loaded, but the problem is all the cache directives are in the main.conf file, so user.conf cannot overwrite them.
Images and media already have expires max, but scripts and styles have expires 1d. Woudn't it be better to change to 1M?
Ok I've found the proper directories to edit the right nginx conf file for my sites. I've changed my cache expiry to 30d and flushed the caches but everything still comes up as 1d. No idea why it's set as 1d by default -- you'd expect js and css files to have a very long expiry time as they are rarely changed.
@kirtangajjar
- So as @tacensi and @b167er have discovered, is there a reason why the cache is being defaulted to 1 day and not allowed to be set to any longer?
Google Pagespeed Insights are very important for a stable web stack and if Google is recommending that the browser cache needs to be leveraged better, then it should be that way by default. Or at least let us change it.
I get it, it's still RC1 and all, but is this issue on the radar and set to be fixed?
Yes. We're tending to all the issues and this is set to be fixed before the stable release.
@Endda Closing this issue as it has been fixed in v4.0.