Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  40] [ 5]  / answers: 1 / hits: 188552  / 13 Years ago, wed, february 15, 2012, 12:00:00

I am trying to optimize a site performance by consolidating and compressing the CSS and JS files. My question is more about the (concrete) steps on how to achieve this, given a real situation I was facing (should be typical among other developers too, though).



My page references several CSS and JS files like the following:



<!--
It's easier to work on smaller files during development.
Hence, the multiple CSS and JS files.
-->
<link type=text/css rel=stylesheet href=/css/main.css />
<link type=text/css rel=stylesheet href=/css/secondary-1.css />
<link type=text/css rel=stylesheet href=/css/secondary-2.css />

<script type=text/javascript src=/scripts/js/main.js></script>
<script type=text/javascript src=/scripts/js/adapter/adapter.js></script>
<script type=text/javascript src=/scripts/js/adapter/title-adapter.js></script>


For the production release, I'd like to combine the 3 CSS files into one and minify it using e.g. YUI Compressor. But then, I'd need to update all pages that needs these 3 files to reference to the newly-minified CSS. This seems error-prone (e.g. you're removing and adding some lines in many files). Any other less-risky approach? The same issue for the JS files.


More From » css

 Answers
16

I ended up using CodeKit to concatenate my CSS and JS files. The feature that I find really useful is the ability to do the concatenation upon file save; because it monitors the respective CSS / JS assets. Once I got them properly combined e.g. to 1 CSS and 1 JS files, all other files simply can refer to these 2.



You can even ask CodeKit to do on-the-fly minification / compression.



Disclaimer: I am not affiliated in any way with CodeKit. I randomly found it on the web and it has served as a great tool in my development process. It also comes with good updates since I first used it more than a year ago.


[#87453] Tuesday, February 14, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diontajm

Total Points: 391
Total Questions: 104
Total Answers: 104

Location: Netherlands
Member since Mon, Jun 7, 2021
3 Years ago
;