1

Google complains on leverage browser caching on the following files:

Leverage browser caching for the following cacheable resources:
https://www.googletagmanager.com/gtm.js?id=GTM-xxxxxx (15 minutes)
https://www.googleadservices.com/pagead/conversion_async.js (60 minutes)
https://www.google-analytics.com/analytics.js (2 hours)

I have the following in my .htaccess file which should set all files to 2 weeks:

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

I verified that I have the mod_expires module enabled.

In Cloudflare I have Browser Cache Expiration set to 2 hours.

  • Are you sure it’s your assets the tool is complaining about? Amusingly it’s usually Google’s scripts (GA/GTM/etc) that are to blame in my experience – Clive Jun 8 '18 at 17:03
  • ^ this. I’ve never had much trouble outside of scripts like that. – Kevin Jun 8 '18 at 17:05
  • @Clive I just updated the question. Yes, it is only the Google scripts that it is complaining about. – albertski Jun 8 '18 at 17:12
3

As these files ain't located on your server you can't do anything about it except wondering why Google Page Speed isn't smart enough to distinguish between on-site resources and external resources. Or why Google itself doesn't do with these files what it suggests should be done with them. I guess, that's some weird kind of paradox ;)

All you could do (highly hypothetically) is to download these files and add them to your own server and let Drupal use these local copies instead of the remote files. But I assume very strongly that this would break the functionality of these services.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.