Running Google's PageSpeed Insights shows that Google does not set proper browser caching headers on it's js file. Setting the file to load locally actually reduces the score because there is no gzipped version of the file. This is a request to implement code to gzip the local js file when it's retrieved from google.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slydevil created an issue. See original summary.

slydevil’s picture

Patch attached

hass’s picture

Version: 7.x-2.1 » 8.x-2.x-dev
Category: Bug report » Feature request
hass’s picture

Status: Active » Needs work
Dom.’s picture

Status: Needs work » Needs review
FileSize
4.52 KB

Here is a port of patch #2 to current dev.
This patch also provides a "Enable Gzip compression" option (just below 'locally cache tracking code' option: it appears only if this option is checked).

To test the patch:
- test your site with page speed : make sure the warning about analytics.js not being gzipped is visible
- patch the module
- navigate to /admin/config/system/google-analytics: enable cache and gzip options
- clear the analytics.js file in files/google_analytics/analytics.js
- run cron
- navigate to a page of your site anonymously
- check that analytics.js.gz is created
- test your site with page speed : make sure the warning about analytics.js not being gzipped has disappeared

lathan’s picture

Status: Needs review » Needs work

my site is deployed on pantheon i can not remove the file in files/google_analytics/analytics.js

should this patch not do that in an update hook?

Dom.’s picture

Status: Needs work » Needs review

Than you will have to wait for next file regeneration. It is rebuilt on cron, every upon a while depending on your configuration.

The last submitted patch, 2: 2571481-1.patch, failed testing. View results

hass’s picture

Status: Needs review » Needs work

I think this is too complicated. If we know core does gzip'ing of JS we can also do it the same way. I think there is no additional setting required at all.

hass’s picture

I guess everything we need to do is saving a .gz file in the same folder

core .htaccess will manage the rest:

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
hass’s picture

Status: Needs work » Fixed

  • hass committed 21f1b89 on 8.x-2.x
    Issue #2571481 by slydevil, hass: Locally cached file is not gzipped
    

  • hass committed d03c4d5 on 8.x-2.x
    Issue #2571481 by hass: Uninstall test updated
    

  • hass committed de44669 on 7.x-2.x
    Issue #2571481 by slydevil, hass: Locally cached file is not gzipped
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.