4

I am trying to figure out how to achieve compression and minification for all my js files. Currently i have them in a hook plugin under /html/js/mycustomjs/ folder.

I understand that liferay has its own mechanism to compress javascripts, in barebone.jsp or everything.jsp, and found the list of files declared in the javascript.barebone.files and javascript.everything.files properties on portal.properties.

The question is, can i use this mechanism to compress js files of my own ? should i override such properties in the portal-ext.properties ? Or should i just use the MinifierFilter by myself ?

Moreover, is a hook plugin the right place to put js files that i want available on all of the portal's sites?

madhead
  • 31,729
  • 16
  • 153
  • 201
madoke
  • 873
  • 11
  • 25

1 Answers1

3

Override the javascript.bundle.dependencies= and javascript.bundle.ids= properties in portal-ext.properties, see http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/javascri-3

Something like this:

javascript.my.files =\  
   jquery-1.8.3.js,\
   my-script.js

javascript.bundle.ids=\
   javascript.barebone.files,\
   javascript.everything.files,\
   javascript.my.files  


javascript.bundle.dependencies[javascript.barebone.files]=javascript.my.files

Furthermore, I don't think that the hook plugin is a right place for such requirements. My opinion the better way is to put the javascripts central to the theme.

Mark
  • 17,887
  • 13
  • 66
  • 93
  • i ended up choosing this solution and creating a jsp of my own, to include all the javascripts, by adding this jsp to the url regex of the minifier filter in liferay-web.xml. As to the javascript placement in the theme, that would not work for multiple websites, so i ended up by keeping them in the hook. Thanks for the feedback – madoke May 15 '13 at 12:26
  • @Mark how can you include javascript files contained in a theme? I can see how this works with a hook because it will include it with the javascript in ROOT/html/js but what do the paths to the javascript files need to look like in `javascript.my.files` if the files are in the theme? – clav Jun 05 '14 at 21:46