4
app.get('/my_profile_picture', function(req,res){
    getPicture(req.user.id, function(url){
        res.redirect(url);  
    });
});

This is my code. However, when the user changes his profile picture, the browser still goes to the old picture's URL. It's because the browser has the "redirect" cached or something.

How do I change the response in Express so that there is no cache at all?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • See also [How to force Chrome NOT to cache redirects?](http://stackoverflow.com/questions/13553420/how-to-force-chrome-not-to-cache-redirects?) - unanswered at this time. – Myrne Stol May 22 '13 at 10:56

1 Answers1

1

Try setting the redirect to be a 307 redirect (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8) as they shouldn't be cached by default.

app.get('/my_profile_picture.jpg', function(req,res){
    getPicture(req.user.id, function(url){
        res.statusCode = 307;
        res.redirect(url);
    });
});
Intermernet
  • 18,604
  • 4
  • 49
  • 61
  • According to the HTTP spec, 307 should not be necessary to avoid caching. Express by default does 302 for `res.redirect`, and a 302 response "is only cacheable if indicated by a Cache-Control or Expires header field." However, Chrome has [a bug](https://code.google.com/p/chromium/issues/detail?id=103458) which causes redirects to be cached. According to a commenter, this applies to 307 redirects as well. So beware. – Myrne Stol May 22 '13 at 10:53
  • @MerynStol I'm surprised that bug *still* hasn't been fixed! It's over a year and a half old! – Intermernet May 22 '13 at 10:57