Liam
Liam

Reputation: 29760

client side caching happening despite version in url

We seems to be having an issue with a css file caching on the client. I generally stop this from causing issue by adding a version number to the file, i.e.

<link href="Default.css?4.31.0.17051" rel="stylesheet" type="text/css">

But in this circumstance this isn't working and I don't understand why.

The version number was incremented last night from 4.30.0.xxxxx to 4.31.0.17051

Some users, and I've seen it myself, are getting a HTTP 304 response. What's strange is if I inspect it using the IE dev tools it shows a HTTP 304, if I fire up fiddler it doesn't show any request at all.

Content caching is not enabled on the server.

Here's the HTTP header if I do a ctrl-f5:

HTTP/1.1 200 OK
Content-Length: 45861
Content-Type: text/css
Last-Modified: Tue, 23 Jul 2013 14:19:40 GMT
Accept-Ranges: bytes
ETag: "0a61aabaf87ce1:bdba"
Vary: Accept-Encoding
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 30 Jul 2013 16:05:54 GMT

So:


EDIT

I've now touched the file, to update the Last-modified date but it's still not requesting it.

So the page is returning a HTTP 200, so this isn't the page caching as suggested below:

Request:

GET http://www.mysite.com/Agent/Hotel HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: http://www.mysite.com/Agent/Flights
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: www.mysite.com
Connection: Keep-Alive

Response:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 53184
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Date: Wed, 31 Jul 2013 08:33:25 GMT




<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="Default.css?4.31.0.17051" rel="stylesheet" type="text/css" />

.........

Upvotes: 0

Views: 228

Answers (2)

Liam
Liam

Reputation: 29760

So I got a solution but not necessarily an answer.

In the end I updated the tag on the site to:

<link href="Default.css?v=4.31.0.17051" rel="stylesheet" type="text/css">

I'm not sure if adding the v= turning it into a valid querystring was the solution or whether it was just the fact that I altered the URL again solved this issue.

I haven't been able to replicate this issue in staging so I don't really know how or why this started happening.

Upvotes: 0

EricLaw
EricLaw

Reputation: 57125

As noted in my answer that you cited, the F12 Tools can show a HTTP/304 when the response was really served from the cache. If you don't see the request in Fiddler, it wasn't sent over the network.

Are you sure that the page that refers to the CSS file wasn't pulled from the cache? If it were, then you'd still have the old URL reference. (Look carefully at the CSS request's URL in the F12 tools, as the URL will be accurate even if the "304" was not).

Two points: - What does "Why isn't this cache control working?" mean? Your HTTP-response headers don't include any Cache-Control directives. - Changing the Last-Modified date on the server obviously isn't something the client will know about unless it actually issues a Conditional GET request to the server.

Upvotes: 1

Related Questions