How to load minify css into envirn production

My project loaded so much JS and CSS. To improve the performance of my site, I started with YUICompression integrated with Ant build. Therefore, every time I create a project, it creates a mini file with the addition of "-min.js"

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

Now I am changing all the files for loading myscript-min.js in my pages.

Is there any kind of automation or an easy way to upload a minify file.

Thanks in advance!

+6
source share
3 answers

In your code, try to determine the environment (production or development) where you load the page. For example, when developing on the local computer, you can check your IP address, server environment variable (using Apache SetEnv ), script path, etc. Using this data, load the script mini-code (in the production environment) or individual scripts (in your development environment).

I assume you are using a server side scripting language like PHP. If you serve static HTML files, this gets a little more complicated (I think dynamic loading of javascript or something else).

+2
source

If you (can) use PHP in your project, take a look at the minify project. He takes care of most responsibilities. You can use uncompressed versions of your CSS and JS files, minify will compress them on demand when these files are requested via HTTP.

+1
source

If you are using PHP, simply follow these steps:

Edit the apache configuration file on your production machine and add this line to httpd.conf (then restart apache). On shared hosting, you should try .htaccess if you do not have access to httpd.conf.

SetEnv ENVIRONMENT production 

This just adds a variable in apache indicating that you are running in production mode. On your development machine, change the meaning of “production” to “development” or something that makes sense to you.

Then in your PHP file, you can switch between loading full JS files and mini code, for example:

 if(isset($_SERVER['ENVIRONMENT']) && $_SERVER['ENVIRONMENT'] == "production") { ... production minified JS here } else { ... development unminified JS here } 
0
source

Source: https://habr.com/ru/post/889846/


All Articles