本文介绍了使用MVC4捆绑和HTML5异步属性的JavaScript文件异步加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML5对脚本文件异步特性,使异步加载。

HTML5 has an async attribute for script files, to enable async loading.

<script type="text/javascript" src="myScript.js" async></script>

我可以通过引用包像这样利用这跟我的MVC4捆绑。

I can take advantage of this with my MVC4 bundling by referencing the bundle like so.

<script type="text/javascript" src='@Scripts.Url("~/bundles/jquery")' async></script>

但是,这并不意味着是我的脚本在调试模式下,即使捆绑的时候。

But what this does mean is my scripts are bundled even when in debug mode.

那么,如何我可以采取捆绑并没有在调试时失去非微小异步属性的优势。

So how can I take advantage of bundling and the async attribute without loosing non-minification when in debug.

推荐答案

如果您升级到1.1 ALPHA1版本中,可以异步属性只是添加到标记格式或者通过:

If you upgrade to the 1.1-alpha1 release, you can just add the async attribute to the tag format either via:

Scripts.DefaultTagFormat = @"<script src=""{0}"" async></script>"

或把它在希望异步标签

Scripts.RenderFormat(@"<script src=""{0}"" async></script>", "~/bundles/jquery"

这篇关于使用MVC4捆绑和HTML5异步属性的JavaScript文件异步加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:15