PageSpeed Insights wrongly reporting cache policy? - caching

Why is PageSpeed Insights failing the cache policy audit? (I have marked one of the failing resources showing its response headers later):
These are the response headers for the marked resource:
The expiration headers at the top of my .htaccess:
# Caching einrichten
FileETag MTime Size
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 weeks"
ExpiresByType application/javascript "access plus 1 weeks"
ExpiresByType application/x-javascript "access plus 1 weeks"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType image/x-icon "access plus 1 months"
</IfModule>
## EXPIRES CACHING ##

We had one year and worked. I don;t know exact period which tool consider has long time but from https://github.com/wp-media/wp-rocket/issues/1345 sounds like it is 4 months. May be you can try by increasing.
Having best cache policy might be tough & various from use case. Look your requirement and set it accordingly. Page insight tool confirms you are setting properly for 30 days in case your use case is to pass audit itself then try 4 months and incrementing till you pass.
Thanks

Related

How long should we set the HTTP Expires or Cache-control: max-age header?

Let's say if the bundle.js is 750kb, is it true that if you set it to "never expire" or "expire in 10 years", then the browser doesn't need to fetch that file and therefore can make your website and pageload faster?
(By the way, it is said that Cache-control: max-age is HTTP/1.1 and if it and Expires: are both present, Cache-control overrides the Expires header.)
What if you have a weekly or 2-month release cycle, should you set the Expires header to 1 week or 2 months? I was thinking that with a weekly release cycle, some of your JavaScript or CSS files may stay the same, so it may be good to just set it to expire in 6 months or even 10 years? (because one week later it hasn't changed?)
But what if your file changed but the browser doesn't fetch it? Is it true that if you use the ETag mechanism, or if you use bundle.53ae823.js or bundle.2020-03-12-08.js, then you can "force" it to expire by the ETag being different, or the file name being different? What is a good way to set the Expires header length?
You could use all of those techniques at the same time. If you can include a hash in your filenames and the references to them (example of how to do it in webpack), then you can be sure that you can bust the cache whenever you change something.
Then you could set Cache-control: max-age to 31536000 (a year, the max) because you can trust the file with URI to not change (because of the hash, if the file changes ,the URI will too).
And of course you can implement ETAG in order to enable revalidation of the cache. This will still require a request to be sent to your server/CDN, but will save the user having to download the whole file if it hasn't changed.
There is a nice article on this topic, here.

how to increase response time in laravel 5.2?

when filling a form in the software then if it takes more than 5 or 6 minutes it gives me an error like XML HTTP request response. Is there any way to increase the response time. The users of my software are very slow in writing.
please help me......
Place this at the top of your PHP script(php.ini file) and let your script loose!
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
After this, restart your local server
Place beloved code in .htaccess to increase it,
<IfModule mod_php5.c>
php_value max_execution_time 300
</IfModule>

how to get the vector tile by Geoserver?

During these days, I am obsessed by a big problem —— how to get the vector tile by Geoserver? I have looking for many docs and blogs, and there are some useful resource for the problem, the operation is very easy if step by step:
http://suite.opengeo.org/docs/latest/dataadmin/vectortiles/index.html;
But after these operations, I still don't get success, i wonder to konw the reason, if you have some idea, please sharing with me, thanks for your kind~
ps:there is some message from console,maybe it's useful:
about gwc seeding:
10 一月 10:27:45 INFO [seed.SeedTask] - GWC Seeder Thread-4 completed (re)seeding layer cn:roads after 192 tiles and 2 seconds.
10 一月 10:27:45 INFO [seed.SeedTask] - GWC Seeder Thread-3 completed (re)seeding layer cn:roads after 80 tiles and 2 seconds.
10 一月 10:27:45 INFO [seed.GWCTask] - Thread group finished SEED task after 2.578 seconds
I don't have enough reputation, so I copy the message to here instead of sending a image, sorry
//*************************************************************************
I have already added the vector-tiles plugin,
and there are some errors when I request the tiles:
http://localhost:8080/geoserver/gwc/service/tms/1.0.0/cite:DLZXX_2011_PL_10000#EPSG%3A4326#geojson/11/1673/891.geojson 404 (Not Found)
//the code to get vector tiles
var vectorTile = new ol.layer.VectorTile({
//get source
source: new ol.source.VectorTile({
format:new ol.format.GeoJSON(),
tileGrid: ol.tilegrid.createXYZ({
maxZoom:14
}),
tilePixelRatio:1,
url:'/geoserver/gwc/service/tms/1.0.0/'+layerName
+'#EPSG%3A4326#geojson/{z}/{x}/{y}.geojson'
}),
style:initStyle
});
map.addLayer(vectorTile);
Header of each Tile GET request
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encodin: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Cookie: JSESSIONID=9679B11893A04A0ACE21D49D93AB7CDC
Host: localhost:8080
Referer: http://localhost:8080/23DPlatform/index.jsp
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Header of response
Content-Disposition :inline; filename=geoserver-dispatch.text
Content-Encoding: gzip
Content-Type: text/plain
Date: Tue, 10 Jan 2017 13:01:09 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding:chunked
//***************************************************************
Maybe you can read this question, there are some similar
Ionic / Leaflet - Can't get Tiles 404 Not Found (from cache)
I have already got the vector tiles by geoserver and openLayers3.
1)The vector tiles in geoserver(GeoWebcache) are created dynamically, so you
don't need to click the seeding button on GeoWebcache admin page;
2)The projection of your data is a very important param, the default projection in OL3 is EPSG:3857. so you need to make sure the projections(layer,source,tilegrid) are same;
PS:I had written down the process on my blog:
http://www.cnblogs.com/escage/p/6387529.html
sorry, it's Chinese blog, if you have any question about these topic, you can
contact me with email:
ericliuneverlost#163.com

Nginx Cache: how to expire/vary by request date

I've got content that changes depending on the date it is requested on, i.e.
the same content will be served when the page is requested at 2018-09-10T00:00 and 2018-09-10T23:59, but different content will be served at 2018-09-11T00:00 (based on the server time).
Is there a vary http header I can set on the content that will achieve this (set by the upstream server)?
Or is there another way of doing this in nginx (ideally only on certain paths)?
Client-side caching is controlled by setting cache control headers.
See http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires for a discussion of the options. It is possible to specify the time of day using the # prefix. So your config would look something like this for setting expiry at 3:30 pm server time:
location ~* \.(css|js)$ {
expires #15h30m;
add_header Cache-Control "public";
}
If your content expired every hour, you could so something fancy like do a time calculation in lua and set that to an ngx variable which is used by expire.
You need to add a "Expires" header, which you can do in Nginx or in your application. The header would look like this, just as an example:
Expires: Sun, 09 Oct 2016 23:59:59 GMT
In PHP you could generate this with:
header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime(date("Y-m-d 23:59:59"))) . ' GMT');
In Nginx you just need to add the following to your location or server block which serves the specified content:
expires #00h00m;
That way the content would expire at midnight.

Cache-control: why two different max-ages

I'm reading an atom-feed from Twitter. I want to know how often I should consult the feed (i.e. throw it the query URL), in order not to miss any results.
The header cache-control line has two different max-ages:
Cache-Control: max-age=15, must-revalidate, max-age=300
How should I interpret this? Should I poll every 15 seconds, or every 300 seconds?
Any learned comment would be appreciated.

Resources