我使用 DNN 的客户端资源管理将 javascript 和 css 加载到主题(皮肤)中,这样我就可以利用缩小和复合文件,但我需要它们是异步的(非阻塞)。如何才能做到这一点?
So far as I know, there is not a way to use the async
(or defer
) attribute on the <script>
tag that is rendered by the Client Resource Management Framework.
You can add an attribute to the <script>
(or <link>
) tag rendered by the Client Resource Management Framework. Add the attribute HtmlAttributesAsString
to the control, and then separate the attribute name and value with a colon, e.g. HtmlAttributesAsString="async:true"
. One thing to note is that there's a bug where multiple attributes, which are supposed to be allowed via commas, aren't rendered correctly (keep an eye on this pull request https://github.com/Shazwazza/ClientDependency/pull/108 which will fix that, and then need to be integrated into DNN).
您还可以编写脚本,以便它设置一个事件处理程序以在加载页面后执行操作(例如,将代码包装在jQuery(function ($) { … });
)
您还可以使用ForceProvider
财产在DnnJsInclude
控件设置要在底部加载的脚本</form>
元素,而不是朝向顶部<body>
(脚本的默认值)。所以,这可能看起来像这样:
<dnn:DnnJsInclude runat="server"
PathNameAlias="SkinPath"
FilePath="js/theme.min.js"
ForceProvider="DnnFormBottomProvider"
Priority="10000" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)