开发者

jquery include file / split huge file into smaller

I am new to jquery. So far I was coding in guerrilla style, so everything is in one page. File has already over 400 lines, what is the best practice in splitt开发者_如何转开发ing one huge file into small logical parts, and how to do it?

I have started to use jquery-ui-tabs. I would like to put that "component" to another file and then load it to map.

How can I load that another file? I want to load it to variable 'content'.


Unless you want to use components of your page and script in multiple locations, you probably shouldn't split it up, because it just means the browser has to make more requests, each with it's own overhead.

If you have some scripts you've developed that you want to use across pages, put it into a .js file and include it in your page using

<script type="text/javascript" src="scripts/myscript.js"></script>

If you have portions of HTML that you want to use across pages, you can stick it in an html file and fetch it from each page using jQuery's get function, something like:

$.get("mypage.html", function(data){
$("#myDivContainer").html(data);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜