如何确定 Asp.net 页面中包含的重复 Javascript 函数
我有一个使用一些 javascript 函数的应用程序,
由于所有 javascript 都包含在 Masterpage 中,因此页面附带的大多数都是不必要的,并且其中一些是重复的(因为在某些不同的 JS 文件中使用。)
所以我想检查是否有是一种确定重复函数并删除它们的方法吗?
I have an application which use some javascript functions,
As all javascripts include in Masterpage, most of them which comes withpage are not necessary, and some of those are repeated ( cause used in some different JS file. )
So I want to check if there is a way to determine duplicate functions and remove them ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在声明函数时检查该函数是否存在,但您必须更改它的工作方式。
而不是
do
并且您仍然可以调用它
所有这些都可以使用正则表达式通过查找和替换添加到您的文件中,所以我认为这很容易:)
You can check if the function exists when declaring a function, but You have to change the way it works.
instead of
do
and You can still call it
All this can be added in Your files with a find&replace using regexp, so I consider this easy :)
不幸的是,除非它们被命名相同,或者引用相同的类或 ID,否则这是极其困难的。但是,如果它是重复的,它应该属于这些匹配之一。我这么说是因为在我们的项目进行了重大转换之后,我返回并将所有 javascript 清理到漂亮的命名空间中,并遇到了同样的问题。
这个答案很糟糕,我道歉:
Ctrl+Shift+F
。搜索相同的函数名称,或者如果您认为它具有不同的名称/相同的函数,则搜索相同的类/ID。我发现搜索函数名称、
#id
和.class
是最有效的。还要从搜索中排除 .cs 文件。这将最大限度地减少时间,因为前面的#
和.
仅在 jQuery 中使用时才会出现,但这仍然是一个非常手动的过程。我希望有人在这里有更好的解决方案,如果他们这样做了,我会觉得自己像个白痴,但老实说,我在 VS 2008 中找不到更好的方法来做到这一点。
Unfortunately, unless they're named the same, or reference the same classes or IDs, this is extremely difficult. But, if it's a duplicate it should fall under one of those matches. I say this because after a major conversion in our project I went back and cleaned up all the javascript into nice namespaces and had this same issue.
This answer is going to suck, and I apologize:
Ctrl+Shift+F
. Search for the same function names, or the same classes/IDs if you think it has a different name/same function.I find searching for function name,
#id
and.class
to be the most productive. Also exclude .cs files from your search. This will minimize the time since the preceeding#
and.
will only appear when using in jQuery, but it's still a very manual process.I hope someone has a better solution here, and if they do I'll feel like an idiot, but I honestly could not find a better way in VS 2008 to do this.
如果两个脚本中的函数具有相同的名称,或者是对象的命名方法,则在解释第二个脚本时,第一个函数将被第二个函数替换。
您不会有两个相同的函数“占用空间”,而只有一个。
If the functions from two scripts have the same name, or are named methods of an object, the first function will be replaced by the second when the second script is interpreted.
You will not have two identical functions 'taking up space', but only one.
从问题中不清楚您是否使用 Webforms 还是 MVC。无论哪种情况,您都希望使用某种脚本管理器。
对于 MVC,我发现这研究了同样的问题: A Simple ScriptManager for ASP.NET MVC
对于Webforms,呃,不确定,我得再去做作业了
Its not clear from the question if you're using Webforms or MVC. In either case you want to be using a script manager of some sort.
For MVC I found this researching much the same problem: A Simple ScriptManager for ASP.NET MVC
For Webforms, erm, not sure, I have to go do my homework again