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

。_饼干妹妹 提交于 2019-12-03 10:48:06

问题


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


回答1:


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.




回答2:


  • 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



来源:https://stackoverflow.com/questions/14070580/how-can-i-minify-html-css-and-javascript-files-in-docpad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!