0

I am setting up a site that relies on a lot of javascript items and i want to try and set it up so the pages only call what they need. there are different types of functionality so i am goig to break them into their own js files to make it easy to use. For example if there is a drag and drop functionality then i will include the js file for drag and drop. within that will be a generic call using a class to turn on the functionality. This way it is only used on a page that uses drag and drop.

This gets more compacted when i have ajax calls some are on change events on a select for example while others are on a button. I could separate these into different files for each type perhaps.

my concern is if a call needs more parameters to be passed or a different url then where does this code go to make the call?

I don't really want to have code within the page itself if i can help it.

I would love to hear your thoughts on how to best set this up

4

3 回答 3

1

RequireJS可能是你的答案:

RequireJS 是一个 JavaScript 文件和模块加载器。它针对浏览器内使用进行了优化,但也可以在其他 JavaScript 环境中使用,例如 Rhino 和 Node。使用像 RequireJS 这样的模块化脚本加载器将提高代码的速度和质量。

于 2012-07-14T18:51:20.477 回答
0

这听起来类似于我正在做的事情,所以这里我做了什么:

  • 一个包含几乎无处不在的函数的中心文件。
  • 包含在多个地方使用但不值得在任何地方都包含的文件的文件夹。
  • 包含仅在一页上使用的文件的文件夹。

然后,只需包含必要的<script>标签即可!

于 2012-07-14T18:51:39.900 回答
-1

嗯,你看过现有的框架http://speckyboy.com/2010/05/17/15-javascript-web-ui-libraries-frameworks-and-libraries/吗?

于 2012-07-14T19:09:57.010 回答