Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injecting response times into view templates #9

Open
kevinSuttle opened this issue May 5, 2015 · 5 comments
Open

Injecting response times into view templates #9

kevinSuttle opened this issue May 5, 2015 · 5 comments
Assignees

Comments

@kevinSuttle
Copy link

Reminder: https://stackoverflow.com/questions/30019235/how-to-access-all-response-times-on-every-route-in-express-4/30029024#30029024

Thanks @dougwilson.

@dougwilson
Copy link
Contributor

So you cannot access the response time until you've actually responded. I can add an API so you can access the "total elapsed time since the request arrived" which will be sort of like a response time. Would that work?

@dougwilson dougwilson self-assigned this May 5, 2015
@kevinSuttle
Copy link
Author

I'm not sure I would know until I saw it in action. Maybe I should leverage https://developer.mozilla.org/en-US/docs/Navigation_timing on the client instead, but I don't know if that's battling the same race condition.

@dougwilson
Copy link
Contributor

We could have this module attach a function to the req object or something. I'm just trying to brainstorm it out with you :) like maybe req.elapsedTime() or something?

It may also be useful to know that since this module normally does response time, and response time is not actually available to your code until you actually... respond, then there is a work-around with the existing code: build all your response headers and explicitly res.writeHead() to respond with the headers, then build your view at which point res.getHeader will have the response time, of course, since you've already started to respond.

@kevinSuttle
Copy link
Author

Yeah, we can try req.elapsedTime.

@dougwilson
Copy link
Contributor

Hi @berkantipek yes, that won't work, which is why this issue is open. The function is called after your view has already been rendered (because rendering the view takes time, which contributes to the response time... you don't know the response time until after you have performed all actions involved in responding, including rendering your view).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants