0
votes

We have a Liferay portlet application with many different portlets deployed.

If have a single portlet that needs a static .js file served how can I add this to only the portlet in question?

Previously we had added .css/ and .js files included by portlets to the theme. In this case only one portlet needs this file. Is it possible to include this file and serve it statically within a .war deployed for a single portlet?

2

2 Answers

1
votes

You can declare required JS or CSS files in liferay-portlet.xml. This file has options for adding them to the header or footer of the page. Look up the very well documented DTD of that file to figure out the options and positions.

0
votes

You can also do as you suggested in put the js file in a 'static resources portlet' to be consumed by all of your other portlets like a simple CDN.

Remember that to access the js file you will need to hit the portlet context so: localhost:8080/static-resources-portlet/js/awesome.js