Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Initialize Static Routes before session initalization #1109

Closed
@tmfelwu

Description

There is a very good explanation for this here

Avoid Sessions for Static Resources
I learned that if you add the session middleware before your static directory, Express will generate sessions for requests on static files like stylesheets, images, and JavaScript.
If a new visitor without a session loads a page with 10 static files, the client's browser will not yet have a cookie and will send 10 cookieless requests all triggering Express to create sessions. Ouch! So that's what was happening... If you haven't done something smart to detect bots and scrapers, things can blow out pretty quickly!
Simply put your static files first, or better yet on a CDN that has nothing to do with your Node.js app and your session collection should stay much healthier

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions