Opened 7 years ago

Closed 7 years ago

#15626 closed Bug (duplicate)

Cache middleware doesnt work with pages contain google analytics script

Reported by: homeip127@… Owned by: nobody
Component: Core (Cache system) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


How it appears:
Every request page is taken from cache (cache hits rate increasing), but then it is generated again and put into cache what causes growth of memory occupied by cache.

How to reproduce:

  1. Setup cache settings:
CACHE_BACKEND = 'locmem://'
# or
CACHE_BACKEND = 'memcached://localhost:9450'



now cache will work as expected
(First response updates cache backend and return 200 (ok), then 304 (not modified) every request during 1 minute)

  1. Now install Google analytics script into template.
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345678-9']);
  _gaq.push(['_setDomainName', '']);

  (function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Page must be open with browser that supports JS and local cache turned off.

Now every request hits cache, than view, database, updates cache and returns response.
in response http headers:

Etag is changing everytime (but content of page is not changed)
Last-Modified sets to current server time
Expires sets to current time + max age

Conditional requests If-Not-Modified-Since  and If-None-Match are always returning 200 OK response.

Next, if turn off JS in browser (for example install NoScript in Firefox) cache works fine, conditional requests get 304. Found this bug in Firefox, Opera, Chrome.

Change History (6)

comment:1 Changed 7 years ago by anonymous

Needs tests: set

comment:2 Changed 7 years ago by anonymous

I think this issue is related with another ticket:

comment:3 Changed 7 years ago by Luke Plant

Resolution: needsinfo
Severity: Normal
Status: newclosed
Type: Uncategorized

Django's cache middleware doesn't look at the content of your template, so something more complicated must be going on. If you are sure this is really happening, please put together a sample project that will allow us to quickly verify this behaviour. Thanks.

comment:4 Changed 7 years ago by Chris Beaven

Type: UncategorizedBug

comment:5 Changed 7 years ago by anonymous

Easy pickings: unset
Resolution: needsinfo
Status: closedreopened
UI/UX: unset

comment:6 Changed 7 years ago by anonymous

Resolution: duplicate
Status: reopenedclosed

This is a duplicate of ticket #9249.

Note: See TracTickets for help on using tickets.
Back to Top