This is not the same delay experiences when the first request arrives, but this is a delay that is experienced each time a Razor based view is accessed for the first time, it can take a second or two. All subsequent requests to that view are very fast. This happens even for simple views that are not doing any kind of programmatic work (such as accessing a database etc).
当第一个请求到达时,这不是相同的延迟体验,但这是每次首次访问基于Razor的视图时所经历的延迟,可能需要一两秒钟。对该视图的所有后续请求都非常快。即使对于不做任何编程工作(如访问数据库等)的简单视图,也会发生这种情况。
I've already ensured that debug=false
in the compilation tag under system.web in the config file.
我已经在系统下的编译标记中确保了debug=false。配置文件中的web。
I've also removed set Razor as the only view-engine via the Global.asax
我还将set Razor从Global.asax删除为唯一的视图引擎
What could be causing this delay? This seems like a problem experienced in the old asp.net 'website' days before it moved to a 'web application' where each .aspx.cs codebehind was compiled at deployment rather than at runtime. Does Razor still suffer from this?
是什么原因导致了这次延误?这似乎是以前asp.net 'website'中遇到的问题,在它转移到一个'web应用'时,每个.aspx。cs codebehind是在部署时而不是运行时编译的。剃刀还受这个折磨吗?
3 个解决方案
#1
28
The issue is caused by the parsing and compilation of the Razor views. Once views are compiled, they execute very quickly. Views are only parsed and compiled on the first request for the view, or if the view has been modified since the last compile.
这个问题是由Razor视图的解析和编译引起的。一旦视图被编译,它们就会执行得非常快。视图只对视图的第一个请求进行解析和编译,或者视图自上次编译以来被修改。
You can resolve this on a deployed WebApp by precompling your views as a part of your Publish process. See the image below on how to do it in VS2012, using the standard publish dialog.
您可以在已部署的WebApp上解决这个问题,方法是将视图作为发布过程的一部分进行预补。请参阅下面的图片,了解如何在VS2012中使用标准发布对话框进行此操作。
You can select the updatable option if you wish, but for a production site I wouldn't recommend it.
如果您愿意,可以选择可更新选项,但是对于生产站点,我不推荐它。
#2
2
Webgrease. It minifies your production js and css bundles on first load, then caches them. Problem is that when the minification has errors it will try to compile every time, running whatever error routines are in there. There is no bug report and the only way of finding out this is happening is by directly opening the references and seeing stuff like:
Webgrease。它会在第一次加载时缩小您的生产js和css包,然后缓存它们。问题是,当缩小有错误时,它会尝试每次编译,运行错误例程。没有错误报告,唯一的发现方法是直接打开引用并查看如下内容:
/* Minification failed. Returning unminified contents.
(69,1): run-time error CSS1019: Unexpected token, found '@import'
(69,9): run-time error CSS1019: Unexpected token, found '"variables.less"'
(70,1): run-time error CSS1019: Unexpected token, found '@import'
Which (in the above case) reveals that your unnecessary .less or .sass files have been published - which is usually the result of wildcard bundling. Wildcard bundling will cost you more time than it saves.
其中(在上面的例子中)显示您不必要的.less或.sass文件已经被发布——这通常是通配符绑定的结果。通配符绑定将花费您更多的时间而不是节省。
#3
0
Parsing views can be slow. Have you tried using RazorGenerator
to compile your views?
解析视图可能很慢。你试过使用RazorGenerator来编译你的视图吗?
Type install-package RazorGenerator
in the NuGet Package Manager Console, or install it via NuGet manually here.
在NuGet包管理器控制台输入安装包RazorGenerator,或者在这里通过NuGet手动安装。
#1
28
The issue is caused by the parsing and compilation of the Razor views. Once views are compiled, they execute very quickly. Views are only parsed and compiled on the first request for the view, or if the view has been modified since the last compile.
这个问题是由Razor视图的解析和编译引起的。一旦视图被编译,它们就会执行得非常快。视图只对视图的第一个请求进行解析和编译,或者视图自上次编译以来被修改。
You can resolve this on a deployed WebApp by precompling your views as a part of your Publish process. See the image below on how to do it in VS2012, using the standard publish dialog.
您可以在已部署的WebApp上解决这个问题,方法是将视图作为发布过程的一部分进行预补。请参阅下面的图片,了解如何在VS2012中使用标准发布对话框进行此操作。
You can select the updatable option if you wish, but for a production site I wouldn't recommend it.
如果您愿意,可以选择可更新选项,但是对于生产站点,我不推荐它。
#2
2
Webgrease. It minifies your production js and css bundles on first load, then caches them. Problem is that when the minification has errors it will try to compile every time, running whatever error routines are in there. There is no bug report and the only way of finding out this is happening is by directly opening the references and seeing stuff like:
Webgrease。它会在第一次加载时缩小您的生产js和css包,然后缓存它们。问题是,当缩小有错误时,它会尝试每次编译,运行错误例程。没有错误报告,唯一的发现方法是直接打开引用并查看如下内容:
/* Minification failed. Returning unminified contents.
(69,1): run-time error CSS1019: Unexpected token, found '@import'
(69,9): run-time error CSS1019: Unexpected token, found '"variables.less"'
(70,1): run-time error CSS1019: Unexpected token, found '@import'
Which (in the above case) reveals that your unnecessary .less or .sass files have been published - which is usually the result of wildcard bundling. Wildcard bundling will cost you more time than it saves.
其中(在上面的例子中)显示您不必要的.less或.sass文件已经被发布——这通常是通配符绑定的结果。通配符绑定将花费您更多的时间而不是节省。
#3
0
Parsing views can be slow. Have you tried using RazorGenerator
to compile your views?
解析视图可能很慢。你试过使用RazorGenerator来编译你的视图吗?
Type install-package RazorGenerator
in the NuGet Package Manager Console, or install it via NuGet manually here.
在NuGet包管理器控制台输入安装包RazorGenerator,或者在这里通过NuGet手动安装。