0

We normally load JavaScript files as:

<script type="text/javascript" src="js/a.js"></script>
<script type="text/javascript" src="js/b.js"></script>
<script type="text/javascript" src="js/c.js"></script>
<script type="text/javascript" src="js/d.js"></script>

This will make 4 request-response calls. Is there a way "other than compressing those files into one", to reduce the number of GET calls? Something like following:

<script type="text/javascript" src="js/a.js, js/b.js, js/c.js, js/d.js"></script>

I saw such an example on Hacker News (news.ycombinator.com) some months ago but can't seem to find it now.

3
  • No, you have to combine them yourself at the server. Commented Sep 13, 2014 at 13:04
  • if you're using .net there is a feature called bundling where it both combines and minifies files, depending on your server side language used (if any) there may be similar features for those languages Commented Sep 13, 2014 at 13:04
  • if loading-time is issue, you could load them async. Commented Sep 13, 2014 at 13:08

1 Answer 1

0

If the purpose is reducing the GET requests, then this question is related to HTTP, not HTML. HTML standards does not define how these files are requested, but only how they are processed.That means, changing the script tag definition isn't a good way to solve the problem.

The practical way is to combine js files at server side. But there are also efforts on improving HTTP or replacing it. For example, the SPDY protocol that Google is trying on Chrome has the function to transfer resources using only one connection. (And HTTP/2, based on SPDY, as wikipedia said) I believe there are other projects like that.

P.S. about the hackernews example you mentioned, I haven't seen one but I can imagine how it works. It might be a client-side script and a server-side library. The script analyzes this kind of script tag and send request of specific syntax. The lib recognizes and captures this request and feed back dynamically combined sources. That's only an automated server-side combo.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.