-
Notifications
You must be signed in to change notification settings - Fork 483
SSR performance optimization - caching #811
Comments
We discussed this a bit over here #795 |
Thank you so much @Toxicable for quick response. Actually I have already gone through it. But for each request we have to bootstrap the app on server. Which increases the time to first byte for server rendered pages in our case google page speed reports 0.8-2 sec as server response time with warning color. I am not sure what could be the best server response time for server rendered page of a real world angular app for both cases i.e. with and without http call, but I believe search engines consider 0.2-0.4 sec as good server response time. So, increased time to first byte certainly will have negative impact on SEO. For large websites, we cant directly push contents to CDN in advance, and normally CDN would cache after first request. So, if the first request for a page comes from search engine it will notice delayed response from server. Have you checked this video from Walmart on React plugin https://www.youtube.com/watch?feature=player_embedded&v=sn-C_DKLKPE , it seems that they are not actually caching the complete response. |
Thanks for that, some interesting ideas going on there that I think would warrant more investigation, however I don't think they're achievable at the moment and other issues do take priority. But purely spit balling here, this might be something like how component caching might work in Angular: For the time being I still think normal caching is the way to go, take a look here https://www.youtube.com/watch?v=geckI2J6naM |
Right now we are using Varnish to cache the output of each page. This works great, but is definitely a more advanced setup considering we need to have varnish cluster setup and implement an X-Cache-Tag system based on all the API's used to render the page. As well as needing to bust the cache when a tag is updated in the CMS More documentation or a caching layer would be a nice addition to the Universal platform |
Thank you @Toxicable and @patrickmichalina . @Toxicable I completely agree that for output cache we already have different options; some already built in the platform for example for .net we have Outputcache, we can also use other options such as Varnish as suggested by @patrickmichalina. Similarly CDN is another options for content caching. But, like in browser when the Angular app (without ssr) is initialized the subsequent navigation between different pages is really very quick, almost instant; reason being that for subsequent navigation, the same app instance is being used and we don't have to go through the bootstrap process again and again. I have absolutely no idea if this is achievable or not, but what if when on server and app is bootstrapped for first request, we could somehow cache that instance and then use that for subsequent requests. |
@naveedahmed1 @Toxicable I thought I'd circle back and share some code that allows HTTP caching based on pages drawn with 1...N http requests. The HttpInterceptor linked below captures any API response that returns an entity with a "Cache-Tag" header. As an example, lets say you hit |
+1 on the request from OP. Caching as a separate layer seems good, but the initial Angular bootstrap, on every incoming request, adds a lot of overhead. For very dynamic / realtime content caching is not always an option, causing many / all requests to end up in renderModuleFactory. My ideal solution would possibly involve bootstrapping the app once, and then using that same app instance for multiple requests. pseudocode:
This has the issue where the ngApp is potentially stateful, so it would only work if building the app in a particular way (e.g. with @ngrx/store you could just set the entire store state to your known good initialState). |
I've played around |
@vikerman @CaerusKaru any progress on this? |
This is an interesting point to keep in mind, did someone find any workaround? |
Does IVY helps in this regard in any way? |
@aescarcha were you using AOT when benchmarking? |
@patrickmichalina no I wasn't, I built with
|
I would try it with AOT - this means less CPU cycles during a render since the component templates are already ready for output. |
I think '--prod' already has AOT enabled. |
Hi, It would be very helpful if someone could suggest a possible solution |
Closing as providing caching is not really in the roadmap of this project. Caching is a complex subject and there are already already a number of services that provide good caching such as CDNs. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
It seems that Angular expects to construct a new app platform instance to serve each request. Which means that the bootstrap process is performed for each request. Is it possible to have some sort of cache so that the bootstrap is performed only for the first request.
I think react community is addressing similar issue for react through this plugin from Walmart Labs:
https://github.com/walmartlabs/react-ssr-optimization
The text was updated successfully, but these errors were encountered: