3

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>
9
  • 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) Commented Sep 4, 2012 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. Commented Sep 4, 2012 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. Commented Sep 4, 2012 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. Commented Sep 4, 2012 at 15:45
  • ok, so @milo5b, any other way to Reduce HTTP Requests? something like jquery $.getScript? Commented Sep 4, 2012 at 16:03

1 Answer 1

2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.