solidusjs / solidus

A simple server that generates pages from JSON and Templates
MIT License
28 stars 7 forks source link

Pages aren't cached because ETags constantly change #55

Closed pushred closed 11 years ago

pushred commented 11 years ago

ETags set for pages currently change on every page load. For example:

etag: "-312921103"
etag: "-1639438051"
etag: "-1538283136"
etag: "-1967886355"

This means that the efforts of cache mechanisms are thwarted because we're telling them the content is constantly changing even if it isn't. We're missing Expires/Cache-Control headers currently however (#54) so in the case of Edgecast at least the pages are being cached for 7 days, masking this issue.

ETags should only be updated when resource data changes or a site is redeployed.

pushred commented 11 years ago

Using Last-modified instead of ETags is preferred by Edgecast. I'd second that preference because it's actually informative.

Fauntleroy commented 11 years ago

What page were you looking at that had such unstable ETags?

Fauntleroy commented 11 years ago

The ETags seem fairly consistent, but they do change every once in a while with no easily discernable changes. I'm thinking changes in the context or its processing (which are generally passed to the page proper via solidus.context) cause the ETag to be invalidated fairly often.

pushred commented 11 years ago

Ahh, that makes sense. In the case of http://keithurban.review.sparkart.com I'm getting a new ETag on every page load, probably because of the relative date calculation happening here:

var now     = new XDate(true);

var seconds = parseInt( utcDatetime.diffSeconds( now ) ),
    minutes = parseInt( utcDatetime.diffMinutes( now ) ),
    hours   = parseInt( utcDatetime.diffHours( now ) ),
    days    = parseInt( utcDatetime.diffDays( now ) );

In the case of http://bravado.review.sparkart.com you're calling underscore's shuffle. http://www.sparkart.com is mostly static though aside from the Kippt resource, as long as that doesn't change I'm only seeing 2 ETags in the mix — 1 for each Servo that I'm being tossed between.

pushred commented 11 years ago

Behavior-wise this is reasonable and perhaps even necessary in some cases where such to-the-second variability may be needed. But does a developer even have any tools to control this when writing their code other than eliminating any such randomizing/time relative code?

Is it possible to override the ETag Express sets with one such as the 5 minute interval set in #54?

Fauntleroy commented 11 years ago

ETag can be set manually to whatever we want it to be. Famously, it was used to create secret tracking cookies for advertisers in the past. This is probably why it's fallen out of favor and it ultimately ignored these days.

Fauntleroy commented 11 years ago

@pushred are we still having these issues?

pushred commented 11 years ago

I think we're good!