Reputation: 33
im extremely curious about exceptional situation between asp.net mvc (4.7.2) and asp.net core mvc (2.2).
What im doing is:
Create empty asp.net mvc project , add new "TestController" cloned from default "HomeController" , duplicate views of home controller and name View directory as "Test".
doing exactly the same on asp.net core mvc project.
run asp.net mvc project and change url as /Test/Index (the view is exactly the same as Home/Index) and it took ~300ms to run on first time. if i refresh the page it took ~5-6 milliseconds to run.
im doing exactly the same on asp.net core mvc project and it took ~30 ms on first run and ~5-6 ms on every time i refresh.
i tested several cases and i think its all about "First creation of X type of controller".
im working on asp.net on 5-6 years but i've noticed this now. you can say it's no problem just 300 ms , but on the low resourced machine it took ~30 seconds.
what is this all about and how can i reduce this time to asp.net core time (~30ms) ?
EDIT: it turns out its not about the creation of controller. It's about the directories of views. I changed the Index action of TestController's view path with "~/Views/Home/Index" it opened fast (if i rendered any view from this folder before) , but if i "first time render a view from X directory (or sub directory) it works slowly as i mentioned."
i think its all about compiling views (or view directories). but im not figure it out yet.
consequently , if i move all my view files to same directory , this case never happens. but it will be very confusing and not feel right approach.
Upvotes: 2
Views: 119
Reputation: 33
I finally figured it out. It's all about compiling views at starting the application (not at runtime).
And its speeding up your website (especially if you have too many views)
Solution:
Paste these settings to bottom line of the file
<Target Name="BeforeBuild">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
<!-- Remove bin folder -->
<RemoveDir Directories="$(BaseOutputPath)" />
</Target>
Reload the project
Paste this code to global asax > Application_Start
var siteId = "1"; // you can find your own from applicationhost.config
var appVirtualDir = $"/LM/W3SVC/{siteId}/ROOT";
var clientBuildManager = new ClientBuildManager(appVirtualDir, null, null,
new ClientBuildManagerParameter
{
PrecompilationFlags = PrecompilationFlags.Default,
});
clientBuildManager.PrecompileApplication();
Run the project
Upvotes: 0