2

I am using node.js with https://github.com/visionmedia/connect-redis to store session variables in redis.

I ran redis-cli monitor and noticed that on a single page load, there are 3 sets of get and setex commands being executed. The 3 sets come from the 3 http requests made on my page load (favicon.ico, /, and index.css).

My question: Is it normal for a redis get and setex to run on every http request? Each pair contains identical data.

Abadaba
  • 1,456
  • 7
  • 20
  • 30

1 Answers1

2

The 3 HTTP gets that you are seeing are normal for a web application.

You can set a very long expiration date on your favicon.ico so that the browser only requests it once.

For static assets (i.e. CSS, JS, images) you can do the same or put them in a different domain (or subdomain)

Be aware that if you put a very long expiration date on a CSS/JS file the browse will not request it again and you might run into weird "issues" in which you make a change to a CSS/JS file and the browser might not get the updated file. This is one of the reasons a lot of sites "version" their CSS files (e.g. styles-2013-02-17.css) so that they can use a different file name when a change is made.

Hector Correa
  • 26,290
  • 8
  • 57
  • 73
  • Thanks but how does this explain redis doing a get and set? Shouldn't redis only get when a page is requested and not static files? And shouldn't it only set when I explicitly ask it to? – Abadaba Feb 17 '13 at 22:45
  • That's hard to tell without seeing your code. Are you using Express? If so, you might need to declare the static file handler before the session stuff. – Hector Correa Feb 17 '13 at 23:25
  • I am using express, putting the static file handler before my session stuff reduced it to 2 requests. Looks like im getting closer. – Abadaba Feb 17 '13 at 23:32
  • This should help you get rid of the second request (if the second request is for favicon) http://stackoverflow.com/questions/11658035/unable-to-change-favicon-with-express-js/14179888#14179888 – Hector Correa Feb 17 '13 at 23:54
  • That fixed it! Using the favicon solution provided in that link and placing it and the static serving declaration at the very top of app.configure and before the session store fixed the issue. – Abadaba Feb 18 '13 at 00:37