Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:13:11+00:00 2026-05-26T14:13:11+00:00

I am using Nodejs and Express Js. Also I add NowJS to the Express

  • 0

I am using Nodejs and Express Js. Also I add NowJS to the Express Js to do some real-time stuffs.

In the configuration file I have

app.configure('production', function() {
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());});

And I run the application using this command:

$ NODE_ENV=production node app.js

However, the files(images, css, js) seem not to be cached, they are always served as new file.

P/s: I have just tested it with localhost, the cache seems to work on localhost, however, when uploading to the server, the cache is not working anymore.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:13:12+00:00Added an answer on May 26, 2026 at 2:13 pm

    Express is built on Connect, and Connect provides the “static” middleware. Here’s the code under the hood for the caching:

    if (!res.getHeader('Cache-Control')) res.setHeader('Cache-Control', 'public, max-age=' + (maxAge / 1000));
    

    You can find that code here:

    https://github.com/senchalabs/connect/blob/master/lib/middleware/static.js#L147

    So as you can see Express is sending a “Cache-Control” header to the browser, telling him to cache that file for a period. So this isn’t a “load a file once and then always serve it to all clients”, but more of a “tell each client to cache the file the first time he downloads it” (which means all the clients will have to download that file once before it’s cached for them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a real-time website using Nodejs . Currently, I'm using Redis because
I start to look at Node.js. Also I'm using Express. And I have a
I have a Node.js app using Express that stores data in a mongoDB (locally).
I'm using node.js and the less compiler middleware: app.configure(function() { // ... app.use(express.compiler({ src:
I want to append some nodes to an xml document using Linq2XML. The file
I'm writing a node.js app using express and mongoose-auth. When I run my app,
I'm using Jade as templating engine for an app on node.js/express. I don't want
I want to rewrite a complete community website in nodejs,express and nowjs with mongodb.
I am using express in nodejs, and am trying to keep my view rendering
I am building an app on node.js using express, and node-mysql driver. There is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.