Instantly share code, notes, and snippets.

Embed
What would you like to do?
Embedded Google Analytics: Fix “Leverage Browser Caching” Warning on Nginx
<html>
<!-- ... -->
<!-- Embed analytics.js as local file -->
<script src="/analytics.js"></script>
</html>
server {
### ...
location = /analytics.js {
# Proxy to google-analytics.com
proxy_pass https://www.google-analytics.com;
# Custom expires time
expires 1y;
}
### ...
}
@ramonfincken

This comment has been minimized.

Copy link

ramonfincken commented Jul 10, 2016

This is some excellent thinking outside the box :)
Thanks for sharing, I used it to fix a JSON call over http -> https (local) to prevent mixed up http/https from happening (including microcaching to speed up things). You might even use microcaching for tye analytics bit as well :)

@shyd

This comment has been minimized.

Copy link

shyd commented Jul 23, 2017

Awesome! Just had the same idea and found your gist! 👍

@milllan

This comment has been minimized.

Copy link

milllan commented Sep 7, 2017

Doesnt work anymore ?

I get this google error page

  1. That’s an error.

The requested URL /analytics.js was not found on this server. That’s all we know.

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