I suggest using tag libraries, something like http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags4.html#67771 , to accept this. Include your script as:
<script:include src="myscript1.js" /> <script:include src="myscript2.js" /> <script:include src="myscript3.js" /> ..
And use the page option for your system to decide whether to concatenate and minimize scripts. Something like below:
www.yourapp.com/app?debugMode=true
By default, scripts are combined and minimized. If you are a developer working on a project, just add a page parameter, for example debugMode = true. When debugMode is true, just visualize the scripts as they are.
There are many services on the market, such as http://developer.yahoo.com/yui/compressor/ , that can be integrated with your project to do the job for you.
Do not compress scripts every time you load a page. Do it the first time and write it down so that you donβt have to do it every time. At any given time, to rebuild the last script file, just add another parameter, for example: rebuild = true so that all the latest files are minfied and cached. You can do the same with CSS too.
source share