问题描述
我使用DNN的客户端资源管理将javascript和css加载到主题(皮肤)中,这样我就可以利用压缩文件和复合文件,但是我需要它们是异步的(非阻塞)。
I use DNN's Client Resource Management for loading javascript and css into a theme (skin) this way I can take advantage of minification and composite files but I need them to be asynchronous (non-blocking). How can this be done?
推荐答案
您可以 将属性添加到< script>
(或< link>
)标签由客户端资源管理框架呈现。将属性 HtmlAttributesAsString
添加到控件中,然后用冒号分隔属性名称和值,例如 HtmlAttributesAsString = async:true
。需要注意的一件事是存在一个错误,该错误导致应通过逗号允许的多个属性无法正确呈现(请注意,它将解决该问题,然后将其集成到DNN中。)
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 which will fix that, and then need to be integrated into DNN).
您还可以编写脚本,以便它设置事件处理程序以在页面加载后执行操作(例如,将代码包装在 jQuery(function($){…})中;
)
You can also write your script so that it sets up an event handler to perform an action after the page is loaded (e.g. wrap your code in jQuery(function ($) { … });
)
您还可以在 DnnJsInclude $ c $上使用
ForceProvider
属性c>控件将脚本设置为加载到< / form>
元素的底部,而不是加载到< body>的顶部;
(脚本的默认设置)。因此,可能看起来像这样:
You can also use the ForceProvider
property on the DnnJsInclude
control to set the script to load at the bottom of the </form>
element, instead of towards the top of the <body>
(the default for scripts). So, that might look like this:
<dnn:DnnJsInclude runat="server"
PathNameAlias="SkinPath"
FilePath="js/theme.min.js"
ForceProvider="DnnFormBottomProvider"
Priority="10000" />
这篇关于如何在DNN客户端资源管理中使用异步(非阻塞)javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!