Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Forked from sergejmueller/index.html
Last active February 6, 2023 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hofmannsven/90388472e0d0129e1e492b4d478d090e to your computer and use it in GitHub Desktop.
Save hofmannsven/90388472e0d0129e1e492b4d478d090e to your computer and use it in GitHub Desktop.
Nginx proxy configuration for Google Analytics
server {
### ...
location = /analytics.js {
# Proxy to google-analytics.com
proxy_pass https://www.google-analytics.com;
# Custom expires time
expires 1y;
}
}
@mch0lic
Copy link

mch0lic commented Sep 3, 2020

I don' think this solution is good, because browser will cache analytics.js for one year, in that time the script might be updated by google and analytics might suddenly stop working.

While I like this idea of handling this through nginx config, we technically need to download the file, give it unique name e.g. analytics.2020-09-03.js and then regularly download analytics.js from Google and check if content matches the local copy (can be done using cron job), if it doesn't update the file and then update the file name to bust cache to something like analytics.2020-09-04.js.

@hofmannsven
Copy link
Author

@mch0lic Good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment