Expires header for Facebook JS SDK and Google Analytics

We all know that adding future expiration dates for static resources is good practice to increase the speed of loading pages on websites. Thus, we have provided it for all of our resources, but the all-too-widespread Facebook JS SDK and Google Analytics do not and therefore reduce the overall page speed rating.

Snapshop

Examining the headers shows that Facebook does 20 minutes: Cache-Control public, max-age = 1200 Connection continues Application Content-Type / x-javascript; Encoding = UTF-8 Date Tue, 23 Sep 2014 04:46:38 GMT Etag "566aa5d57a352e6f298ac52e73344fdc" Expires Tue, Sep 23, 2014 05:06:38 GMT

and Google Analytics do 2 hours: Key value Reply HTTP / 1.1 200 OK Date Tue, 23 Sep 2014 04:45:49 GMT Expires Tue, 23 Sep 2014 06:45:49 GMT Last-Modified Mon, 08 Sep 2014 18:50 : 13 GMT X-Content-Type-Options nosniff Content-Type text / javascript Server Golfe2 Age 1390 Cache-Control public, max-age = 7200 Alternative protocol 80: quic, p = 0.002 Content length 16,062

Is there a way to forcefully extend their validity?

+6
source share
2 answers

Finally, the solution was to switch to the Facebook rediret API, which does not load their script every time the page loads. This is actually what StackOverflow does here. Start a session in a private / incognito browser and you will see. This link may help: https://developers.facebook.com/docs/php/howto/example_facebook_login

0
source

These scripts have short cache expiration headers because they are updated frequently. When Facebook and Google add new features and fix bugs, they deploy these changes by overwriting existing files (the ones you linked to in your question). This allows users of these services to get the latest features without having to do anything, but this is due to the cost (as you indicated) of the need for short-term cache headers.

You could place these scripts yourself and set headers with a distant future on them, but this will require that you manually update them when changing libraries. This will be very time consuming and often impossible, because most of these updates are not published in the public change logs.

In addition, to do it yourself, perhaps, in the end, it can become a net loss of performance, because you lose the effect of the network cache that you get due to the huge popularity of these services. For example, I would suggest that when most users come to your site , they already have a cached version of these scripts (i.e. it is very likely that in the last two hours, the person who visited your site also visited another site using Google Analytics). On the other hand, if you posted your own version, visitors always had to download your version.

To summarize, I would not go down the road to fix this "problem". This will take a long time and probably will not give you the desired effects.

+5
source

Source: https://habr.com/ru/post/975694/


All Articles