Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable server side rendering on an asp.netcore-spa application?

I am building my application using aspnetcore-spa react-redux boilerplate (can be seen on http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/ )

However the server side rendering takes a lot of time (~30 sec) and I would like to disable it. Can you please tell me how to disable server side rendering without breaking the code?

like image 581
Hasan Avatar asked Sep 27 '16 07:09

Hasan


2 Answers

That template adds the asp-prerender-module tag helper to the <div id="react-app"...> tag in Home\Index.cshtml. If you remove that tag helper you will disable server side rendering.

The tag helper is imported in /Views/_ViewImports.cshtml:

@addTagHelper "*, Microsoft.AspNetCore.SpaServices"

You can do the bundling from the command line before you run the application with...

> webpack --config webpack.config.vendor.js
> webpack

Steve Sanderson gave a presentation on this at NDC Sydney.

The aspnet-prerender-module tag helper is part of SpaServices, which is the basis for all the projects generated by the Yeoman aspnetcore-spa templates. Therefore, this is how you would enable/disable pre-rendering in any of those templates, including Angular 2, Aurelia, Knockout, and React (with Redux). The same would apply to any custom project or template that you create using Node package aspnet-prerendering and the aforementioned tag helper.

like image 175
Eric Lease Avatar answered Nov 13 '22 17:11

Eric Lease


For Angular 2 project I've solved this by removing asp-prerender-module attribute from <app> tag in Index.schtml.

like image 40
Roman Peterson Avatar answered Nov 13 '22 16:11

Roman Peterson