Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I automate Javascript and CSS minification on Google App Engine?

I couldn't find any proper solution for automating Google App Engine CSS and Javascript minification.

like image 934
Ron Reiter Avatar asked Aug 30 '11 05:08

Ron Reiter


People also ask

How do you minify CSS and JavaScript?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

Should I minify CSS and JavaScript?

It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.


2 Answers

If your JS/CSS files are to be used inside an HTML page, then a very good option is to have App Engine optimize your site automatically (minification, bundling, inlining and more) via the experimental "Page Speed" feature. You can turn this on by doing this:

  1. Go to your projects' App Engine dashboard: https://appengine.google.com/settings?&app_id=s~your_project_id

  2. Click on "Application Settings" (bottom left under "Administration" section).

  3. Scroll down to the "Performance" section and locate "PageSpeed Service:". Check the " Enable PageSpeed Service" checkbox and hit "Save".

This will add response filters that will automatically do stuff like combine and minify your JS, turn the minified bundle from a script reference to an inline script (to lesser the count of server requests) and more cool and effortless performance improvments. Read more about this feature here: https://developers.google.com/speed/pagespeed/service/faq

like image 63
orcaman Avatar answered Oct 08 '22 11:10

orcaman


Write a deploy script that makes a copy of your app with minified JS and CSS, and then calls appcfg on it. You shouldn't be minifying it dynamically unless you're generating it dynamically.

like image 28
Nick Johnson Avatar answered Oct 08 '22 11:10

Nick Johnson