Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MVC5捆绑包异步加载CSS_Css_Asynchronous_Razor_Asp.net Mvc 5_Bundles - Fatal编程技术网

使用MVC5捆绑包异步加载CSS

使用MVC5捆绑包异步加载CSS,css,asynchronous,razor,asp.net-mvc-5,bundles,Css,Asynchronous,Razor,Asp.net Mvc 5,Bundles,我在读关于异步CSS加载的文章 我想知道是否有可能在MVC5捆绑包中使用这种行为 我想要实现的是以非阻塞方式下载多个捆绑的CSS文件(这意味着我的页面加载时间更快)在样式帮助程序中有一个方法,您可以在其中设置自己的标记格式 @Styles.RenderFormat("<link href=\"{0}\" rel=\"preload\" as=\"style\"/>", "~/Path/To/My/Bundle") @Styles.Rende

我在读关于异步CSS加载的文章 我想知道是否有可能在MVC5捆绑包中使用这种行为


我想要实现的是以非阻塞方式下载多个捆绑的CSS文件(这意味着我的页面加载时间更快)

样式
帮助程序中有一个方法,您可以在其中设置自己的标记格式

@Styles.RenderFormat("<link href=\"{0}\" rel=\"preload\" as=\"style\"/>",
                     "~/Path/To/My/Bundle")
@Styles.RenderFormat(“,
“~/Path/To/My/Bundle”)

对于完整的工作解决方案,我使用我标记为接受的答案来回答这个问题,但我又添加了一件事,使其100%工作

onload="this.rel='stylesheet'"
例如:

C#文件:

public const string StyleRenderFormat = "<link href=\"{0}\" rel=\"preload\" as=\"style\" onload=\"this.rel='stylesheet'\"/>";
@Styles.RenderFormat(BundleConfig.StyleRenderFormat, "~/myCssBundleName")