Extra and/or duplicate scripts/stylesheets getting included

31 views
Skip to first unread message

Aseem Kishore

unread,
Sep 17, 2011, 4:42:32 AM9/17/11
to expre...@googlegroups.com
We're sometimes seeing the scripts/stylesheets of one view get included in another view. We're using this dynamic helpers middleware to help us include scripts and stylesheets:


It's always worked just fine, but very recently we've started to see this occasional bug. It's so strange; it suggests that somehow one request gets access to another request's closure? We're using Express 2.2.x, so 2.2.2. Any ideas what might be up?

Thanks!

Aseem

Aseem Kishore

unread,
Sep 19, 2011, 3:02:34 PM9/19/11
to expre...@googlegroups.com
Anyone have any ideas? =) Thanks in advance!

Aseem

Aseem Kishore

unread,
Oct 6, 2011, 9:03:38 PM10/6/11
to expre...@googlegroups.com
One last try I guess?

Here are some specifics, for example:

On page /foo, we include foo.css.

On page /bar, we include bar.css.

The bug is that very occasionally, a request to /foo will return both foo.css and bar.css in the response (or the other way around).

We think this happens when there are concurrent requests to /foo and /bar happening at the same time.

Any ideas, suggestions for further debugging, etc. would be greatly appreciated!

Aseem

vision media [ Tj Holowaychuk ]

unread,
Oct 7, 2011, 11:11:37 AM10/7/11
to expre...@googlegroups.com
hmm you must have some shared state, I'll take a peek

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.



--
Tj Holowaychuk
Vision Media
President & Creative Lead

vision media [ Tj Holowaychuk ]

unread,
Oct 7, 2011, 11:12:09 AM10/7/11
to expre...@googlegroups.com
your getBlock(name); is cached in that closure at the process level

Aseem Kishore

unread,
Oct 7, 2011, 4:51:00 PM10/7/11
to expre...@googlegroups.com
Hmm, but that's inside a middleware -- function(req, res, next) { ... } -- so shouldn't it be specific to a single request?

Aseem

vision media [ Tj Holowaychuk ]

unread,
Oct 7, 2011, 4:53:23 PM10/7/11
to expre...@googlegroups.com
oh sorry I missed that it was middleware... duh.. I should have looked at the signature. I think it's because you're using app.helpers() for locals vs res.locals(), so subsequent requests knock out the old helpers

Aseem Kishore

unread,
Oct 7, 2011, 4:53:40 PM10/7/11
to expre...@googlegroups.com
Ohhh snap, is the problem that `req.app.helpers()` sets a function that's *not* specific to that request?

Aseem

Aseem Kishore

unread,
Oct 7, 2011, 4:55:59 PM10/7/11
to expre...@googlegroups.com
Didn't know res.locals() existed! That might be it. Thanks TJ!

Aseem

Aseem Kishore

unread,
Oct 7, 2011, 4:57:00 PM10/7/11
to expre...@googlegroups.com
Just to clarify, res.locals() can also take a function like app.helpers() can?

Aseem

vision media [ Tj Holowaychuk ]

unread,
Oct 7, 2011, 4:58:26 PM10/7/11
to expre...@googlegroups.com
correct. there are essential app-level locals and request-level locals. In 3.x they'll be named appropriately haha, "helpers" was a bad term I brought over from ruby-land so that's a fail for me. In express 3.x it'll simply be:

app.locals.myfunction = function(){}

...
  res.locals.myfunction = function(){};
  next();

blah blah

vision media [ Tj Holowaychuk ]

unread,
Oct 7, 2011, 4:59:02 PM10/7/11
to expre...@googlegroups.com
yup, for 2.x I believe it's res.locals(obj) and res.local(key, val) which manipulate res._locals internally

Aseem Kishore

unread,
Oct 7, 2011, 4:59:20 PM10/7/11
to expre...@googlegroups.com
Awesome, thanks!

Aseem Kishore

unread,
Oct 10, 2011, 2:33:00 AM10/10/11
to expre...@googlegroups.com
This totally fixed it. Thanks again TJ!

Aseem
Reply all
Reply to author
Forward
0 new messages