Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is these way can Reduce HTTP Requests?

multiple javascript files with & symbol

<script type="text/javascript"
src="http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js
&http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>

multiple css files with @ import

<style type="text/css">
@import url(css/style.css);
@import url(css/custom.css);
</style>
share|improve this question
4  
Why don't you combine them instead ? By the way, I don't think every browser will understand the & where did you see that? (and this lead to a 400 bad request from yahoo) –  j0k Sep 4 '12 at 15:34
1  
Load the JS at the bottom of the page: it won't save you requests, but the page will load a lot faster. As j0k said, combine them. Also minify them if they are not already. –  ionFish Sep 4 '12 at 15:36
    
@j0k, ionFish, the problem is the js file like yui and jquery, It is impossible combine them with some software like jsmin.exe, because the licence, and impossible load them in the bottom of the page, many javascript code with relay on them will not work. –  Giberno Sep 4 '12 at 15:41
    
If you can use all your jquery code inside a $(document).ready() function, then you can load the jquery file just before the js/jquery code (as described by ionFish). In some cases that you have some onclick="javascriptcodehere" or similar, and you cannot refactor it to load the script once the document is ready, then you will have to load it on top. Try to use popular CDN for jquery and popular scripts/css: often your visitors will already have the file cached and will not require a full request. –  milo5b Sep 4 '12 at 15:45
    
ok, so @milo5b, any other way to Reduce HTTP Requests? something like jquery $.getScript? –  Giberno Sep 4 '12 at 16:03
show 4 more comments

1 Answer

up vote 2 down vote accepted

The 2 examples are minified versions served from popular CDN, so many visitors will have them in their cache, and therefore no HTTP request will be required.

If you want to combine them, download the files and then you need to do some kind of combining the files on the server side. If you are using .NET SquishIt is a popular choice. If you use PHP minify is an option.

In regard to the CSS files, the above two options support those as well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.