Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I minify HTML, CSS and JavaScript files in DocPad?

Tags:

docpad

I would like to minify HTML, CSS and JavaScript files when I hit docpad generate, how can I do that?

like image 767
Zeno Rocha Avatar asked Dec 28 '12 13:12

Zeno Rocha


People also ask

How do you minify CSS and JS files?

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.

How do you minify a project in HTML?

The easiest way to minify your HTML, CSS and JavaScript in WordPress is to use a plugin. This allows you to optimize your WordPress site files for decreased page load times automatically with a few clicks of a button. There are a lot of plugins out there that will do the job but I will briefly mention a few standouts.

How do I combine HTML CSS and JavaScript?

To link a CSS file with your HTML file, you have to write the next script on your HTML file inside the head tag. To link a Js file with your HTML, you only have to add the source of the script inside the body tag or outside; it doesn't matter.

How do I minify CSS and JS in WordPress?

Alternatively, you can also use Minify Code — a WordPress minify tool that offers separate CSS, HTML, and JavaScript minifiers: Download the files that you want to minify from your website. Save a copy as a backup. Copy the content of the file and paste it to the appropriate minifier tool.


2 Answers

There are a few ways you can go about this. The most prominent and most immediate way is to modify your docpad configuration file to trigger an external tool like grunt to minify your assets via the grunt minify task. Here is a gist that showcases this.

Alternatively, there is also Cloudflare which is an amazing website DNS server that also acts as a CDN for your website's content, and minifies your assets automatically post-deployment. Read more here.

Also, while it isn't minify related, you can also concatenate your scripts with Browserify using this gist. Grunt also has a more straightfoward way of concatenating as well via the grunt concat task.

Eventually, perhaps plugins will do this automatically, but considering the fickleness with concatination it could be a while.

like image 153
balupton Avatar answered Oct 25 '22 17:10

balupton


  • Use gruntjs for JS files. (Grunt will hook up into docpad generate)
  • Use grunt-contrib-mincss for css files.
  • Use grunt-contrib-htmlmin for html files.
  • Use grunt-compress for compressing all files.

For list of all grunt plugins look here: https://github.com/gruntjs

like image 43
przemo_li Avatar answered Oct 25 '22 19:10

przemo_li