gpt4 book ai didi

asp.net - 如何使用 ToolkitScriptManager 复合脚本包含大量 Javascript 文件?

转载 作者:行者123 更新时间:2023-12-02 17:05:17 24 4
gpt4 key购买 nike

如果脚本管理器中的复合脚本包含太多 javascript 文件,您会收到此错误...

“资源 URL 不能超过 1024 个字符。如果使用 CompositeScriptReference,请减少它包含的 ScriptReference 数量,或者将它们合并到单个静态文件中,并将 Path 属性设置为它的位置。”

我知道如何使用旧的 asp:scriptmanager(使用脚本管理器代理)来解决此问题。但如何使用 ToolkitScriptManager 修复它?

<ajaxToolkit:ToolkitScriptManager ID="GeneralScriptManager" CombineScripts="true" CombineScriptsHandlerUrl="Utility/CombineScriptsHandler.ashx" runat="server" AsyncPostBackTimeout="480" EnablePageMethods="true">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="JavaScript/jQuery/jquery-1.4.1.min.js" />
... A whole lot more script references here
</Scripts>
</CompositeScript>
</ajaxToolkit:ToolkitScriptManager>

更新我尝试使用示例应用程序中包含的脚本组合器来执行此操作。我认为这是对的,但我之前已经错了很多次了……不过运气不好。

另一个更新 因此,我认为如果我在单个 ToolkitScriptManager 中包含多个 CompositeScript block ,它可能会将它们全部创建为单独的文件。没有。仍然得到同样的错误。没有人有任何想法吗?当我 Google“toolkitscriptmanager 不能超过 1024 个字符”时,这个 StackOverflow 问题是第 1 个结果...

最佳答案

关于这方面的 MSDN 文档实际上非常好:

The number of script references that a CompositeScriptReference instance can contain is limited by the size of the resulting URL. The URL cannot be longer than 1024 characters.

If you have to work around this limitation, you have two options. The first option is to reduce the number of ScriptReference objects that the composite script contains. The second option is to manually combine the scripts into a single static file. In that case, you can set the Path property to the location of the static file.

如果您想要合并多个物理文件,那么您的做法是错误的 - 请参阅下面的链接 [1]:

You can combine multiple physical script files using that feature, but we really don't recommend it as there is some server overhead related to file monitoring. What you're describing is much better handled by "building" your scripts at compile time instead of doing the combination at runtime. The feature really is for application developers who want to combine existing scripts from various components that they use in their application.

我想要的是一个结合静态 *.js 文件的构建后任务,例如 [2]。

祝你好运。

[1] - http://weblogs.asp.net/bleroy/archive/2008/06/12/script-reference-profiler.aspx

[2] - http://encosia.com/2009/05/20/automatically-minify-and-combine-javascript-in-visual-studio/

关于asp.net - 如何使用 ToolkitScriptManager 复合脚本包含大量 Javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3376063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com