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 8013311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:36:13+00:00 2026-06-04T19:36:13+00:00

I am serving all static content on my app through a subdomain. However, my

  • 0

I am serving all static content on my app through a subdomain.

However, my express app is still setting session cookies on the static content. I tried setting the path like this as per the docs:

app.use(express.session({
    secret: 'your app secret',
    cookie: {
        domain : '.yourdomain.com'
    },
    store: new MongoStore({
        db: 'db',
        host: 'localhost',
        port:config.dbPort
    })
}));

but it still doesn’t work for me. I also tried using ‘path’ :

cookie: {
   path : '.yourdomain.com'
}

but even that doesn’t prevent setting of cookies on static content.

Any ideas on how to remove cookies from all static content?

UPDATE:

Request Headers
    Accept:text/css,*/*;q=0.1
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-US,en;q=0.8
    Connection:keep-alive
    Host:cdn.yourdomain.com
    Referer:http://localhost:8888/
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5

Response Headers
    Cache-Control:public, max-age=86400
    Connection:keep-alive
    Content-Encoding:gzip
    Content-Type:text/css; charset=UTF-8
    Date:Mon, 28 May 2012 09:02:09 GMT
    Last-Modified:Tue, 01 May 2012 03:57:45 GMT
    Server:nginx
    Set-Cookie:connect.sid=d9nEPGiAeSwGFUN2Ra8CGBmq.tPdTQdk7O2UUvO2q%2BEOG2%2Fgh%2FNEdIxtUZYdUN%2FtDmas; domain=www.yourdomain.com; path=/; expires=Mon, 28 May 2012 13:02:08 GMT; httpOnly
    Transfer-Encoding:chunked
    X-Cache:MISS
    X-Edge-Id:353260802
  • 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-06-04T19:36:14+00:00Added an answer on June 4, 2026 at 7:36 pm

    The connect session middleware works this way. Cookies are set regardless of the current host. This is good from a performance point of view, but inherently causes issues like this.

    I see two solutions for this issue:

    • Use Connect’s Vhost middleware. IMO, this is the most straightforward solution. Just create a separate app for cdn.yourdomain.com without including the session middleware for it.

    • Create a wrapper around the session middleware in order to include it only for requests with the correct host. This is a pretty odd solution, and can disturb other middleware like CSRF.

    Anyway, I would say that using Node.js for serving static assets may look like a strange idea. For this, web servers like Nginx are unbeatable in terms of performance and lightness. Requests for static requests should ideally not even reach Node.js.

    —

    FYI, code for the second solution could look like that (untested):

    function hostAwareSessionMiddleware(options) {
      var originalMiddleware = express.session(options);
      if(!options.cookie || !options.cookie.domain) return originalMiddleware;
      var domain = options.cookie.domain;
      if(domain[0] === '.') domain = '(.+)\.' + domain.slice(1);
      var regex = new RegExp('^' + domain.replace('.', '\\.') + '$', 'i');
      return function(req, res, next) {
        if(!req.headers.host) return next();
        if(req.headers.host.match(regex)) {
          return originalMiddleware(req, res, next);
        }
        next();
      }
    }
    
    app.use(hostAwareSessionMiddleware({
      secret: 'your app secret',
      cookie: {
        domain : 'yourdomain.com'
      },
      store: new MongoStore({
        db: 'db',
        host: 'localhost',
        port:config.dbPort
      }
    }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm serving static media content on the same server as my Django app. I'm
I'm serving all of my static content from Cloudfront via my S3 bucket. If
I am serving all content through apache with Content-Encoding: zip but that compresses on
The Facebook app I am running is on app.[domain] domain. All the static content
I've been reading articles about speeding up websites by serving static content from a
I have a special setup where I serve content purely through a static XML
I've recently read an article http://www.ravelrumba.com/blog/static-cookieless-domain/ about Serving Static Content from a Cookieless Domain
I have an ASP.NET (MVC) website that is serving static content (images) as well
We are currently serving a significant part of static content from an alternate (cookiefree)
I'm using Dragonfly to generate thumbnail images in a Rails app. I'm serving all

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.