简体   繁体   English

ASP.NET,结合有条件包含的脚本文件

[英]ASP.NET, combining conditionally included script files

We are working on an ASP.NET CMS project using jQuery as the basis for our client side scripting. 我们正在使用jQuery作为客户端脚本编写基础的ASP.NET CMS项目。

The jquery-1.2.6.js file is the only script file that is always included. jquery-1.2.6.js文件是始终包含的唯一脚本文件。 Other script files are currently included depending on what components the CMS editor is using on a page or page template. 当前包括其他脚本文件,具体取决于CMS编辑器在页面或页面模板上使用的组件。

A lot of the script combiners produce a static script. 许多脚本组合器会生成静态脚本。 If we took that approach we would have to add all possible script files in just in case they were needed. 如果采用这种方法,则必须添加所有可能的脚本文件,以防万一需要它们。 We are not currently using any of the ASP.NET Ajax extensions so have not looked at what that may give us. 我们目前未使用任何ASP.NET Ajax扩展,因此没有研究可能会给我们带来什么。

Anyone got any suggestions? 任何人有任何建议吗?

I have read Combining and Caching multiple JavaScript files in ASP.net but I don't think that covers off the conditional nature of our situation 我已经阅读 了ASP.net中的合并和缓存多个JavaScript文件,但我认为这不能掩盖我们情况的有条件本质

So great I can use ScriptManagerProxies and some methods on the base master Page. 太好了,我可以在基础母版页上使用ScriptManagerProxies和某些方法。 However there is one other thing. 然而,还有另一件事。 Stopping all the ASP.NEt Ajax guff being sent down to the client. 停止将所有ASP.NEt Ajax guff发送到客户端。 I am going to take a look at bleroy's hack until ASP.NEt 4.0 releases 在ASP.NEt 4.0发行之前,我将看看bleroy的黑客行为。

TIA TIA

Pat Long 帕特朗

Working in Sitecore on a site that had multiple scripts for different pages, we created a list of script items in Sitecore, then added a Multlilist field to the Items. 在具有针对不同页面的多个脚本的网站上的Sitecore中工作,我们在Sitecore中创建了一个脚本项列表,然后在“项”中添加了一个多列表字段。 We had a placeholder in the head of the master page, and dynamically added the scripts as they appeared in the multilist field. 我们在母版页的开头有一个占位符,并随着脚本在多列表字段中的出现而动态添加。 We did the same thing with CSS as well. 我们也对CSS做过同样的事情。 It worked out nicely. 效果很好。 (Specifically, it was on http://www.utulsa.edu ) (具体来说,它在http://www.utulsa.edu上

Edit: I misunderstood what you originally meant. 编辑:我误会了你的意思。 It seems like you may need combine and produce all the possible static scripts you need, then dynamically include the one you are looking for, if you're looking for only one script include per page. 似乎您可能需要合并并生成所需的所有可能的静态脚本,然后在每个页面仅包含一个脚本的情况下,动态包含要查找的脚本。

Otherwise, you could just depend on caching to keep your script requests down, and do what you are currently doing 否则,您可以仅依靠缓存来减少脚本请求,并执行当前正在执行的操作

Edit 2: A third thought is you could write your own combiner that will combine scripts on demand, and include the generated (or pre-generated) script 编辑2:第三个想法是,您可以编写自己的组合器,该组合器将按需组合脚本,并包括生成的(或预生成的)脚本

I don't know if this will help you or not, but Scott Hanselman posted on twitter that you could download issues of MSDN Magazine for free . 我不知道这是否对您有帮助,但是Scott Hanselman在Twitter上发布了可以免费下载《 MSDN杂志》的信息 I followed the link and looked through a couple of issues and this month (Feb, 2010), and one of the first articles discusses predictive fetching with jQuery and ASP.NET Ajax. 我浏览了该链接,并在本月(2010年2月)中浏览了两个问题,其中第一篇文章讨论了使用jQuery和ASP.NET Ajax进行预测性获取。

This looks like it could be along the lines of what you're looking for. 看起来可能与您要查找的内容相似。 As far as stopping the AJAX requests, I haven't read the entire article, but I'd assume it mentions something in there (as predictive fetch would have to account for this). 至于停止AJAX请求,我还没有阅读整篇文章,但是我认为它在其中提到了某些内容(因为预测性提取必须考虑到这一点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM