Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load minify css in production envirn

I have been loading so many JS and CSS in my project. To improve my site performance, I started with YUICompression integrated with Ant build. So each time when I build the project it creates minified file with appending"-min.js"

Example: myscript.js after build, new file "myscript-min.js".

Now I have changing all the files to load myscript-min.js in my pages.

Is there any automation or simpler way to load the minify file.

Thanks in Advance!!!

like image 278
Santhosh Avatar asked Jun 06 '11 07:06

Santhosh


2 Answers

In your code, try to determine the environment (production or development) from where you're loading the page. For instance, when developing on a local machine, you can check your IP address, a server environment variable (using Apache SetEnv), script path, etc. Using that data, either load the minified script (in production environment), or the separate scripts (in your development environment).

I am assuming that you're using a server side scripting language, like PHP. If you're serving static HTML files, it gets a bit more tricky (I'm thinking dynamic javascript loading or something).

like image 93
Peter Kruithof Avatar answered Oct 13 '22 06:10

Peter Kruithof


If you (can) use PHP in your project then have a look at the minify project. It takes care of most of the chores. You are free to use uncompressed versions of your CSS and JS files, minify will compress them on-demand when these files are requested over HTTP.

like image 43
Salman A Avatar answered Oct 13 '22 05:10

Salman A