-
Notifications
You must be signed in to change notification settings - Fork 2k
Move static files middleware before sessions #318
Comments
My original pull request didn't move the helmet config, so any static files didn't get the headers provided by helmet. I relooked this changes I made with the goal of having the headers look the same before and after (since this is what helmet affects). I was able to get the same headers and a performance improvement by moving both helmet and express.static before sessions. The stock session functionality (log in/out and restrict access to articles) works with the changes. On my setup, page load times drop from ~4s to ~750ms. Looking at the network performance monitor in the Chrome dev tools, the time decrease comes from faster loads on static files. Headers from request for bootstrap.css with latest meanjs:
Headers with the change I originally proposed:
Headers after moving helmet and express.static (same as original):
|
@bmonty nice catch. LGTM. |
This is broken again. |
@pursual Can you provide more details on what you're experiencing, and how this is broken? |
The session is now initiated before the static routes, and every request for a static file pings mongo. Bottom of config/lib/express.js If you ever wondered why meanjs was slow as hell out of the box, and failed to fully load 5/10 times, this is it. I actually missed the version where it was fixed since last time I used the framework. |
@pursual Yes.The session is initiated before the static routes. https://github.com/meanjs/mean/blob/master/config/lib/express.js#L232-L242 I can confirm that there is a significant performance increase when moving the Helmet & Static routes middleware before the Session. Thanks @pursual for pointing this out. I think was re-introduced during the move from the older structure of 0.3 to 0.4. @lirantal Can you confirm that this indeed does have an impact given our current structure. My performance testing here was very rudimentary. @codydaig @ilanbiala Any special insight into this? |
Pull request submitted, worked fine in my project. |
right, that PR is good, we should merge it. |
I was having a performance problem with reloading a site built off of meanjs. I solved the problem by moving the config for the static files middleware before the sessions middleware. Static files load significantly faster because there isn't session tracking being done for each of them.
The text was updated successfully, but these errors were encountered: