RE: shared js files in different portlet project

Hairi Lani, modificat fa 5 anys. New Member Apunts: 17 Data d'incorporació: 09/04/20 Publicacions recents

Hi all.

Let say I have 2 portlet in different projects. (hq-task-web and branch-task-web)

Both portlet have common js function calculateDateline.js

Can I put this js file in common project so that both portlets can use it? (Except in themes)

 

Thanks

/Hairi

thumbnail
Mohammed Yasin, modificat fa 5 anys. Liferay Master Apunts: 593 Data d'incorporació: 08/08/14 Publicacions recents

Hi ,

One way is to create war mvc portlet and add the js file under /src/main/webapp/main.js, and this js can be referred in any module by script tag

Ex.

<script src="/o/js-util/js/main.js"></script>

 

 
Hairi Lani, modificat fa 5 anys. New Member Apunts: 17 Data d'incorporació: 09/04/20 Publicacions recents

come back with same question.

this make the portlet hang because access this approach is too slow.

If I use compileInclude, it will package in the same bundle?

Because its placed in META-INF

 

Thanks

thumbnail
Olaf Kock, modificat fa 5 anys. Liferay Legend Apunts: 6441 Data d'incorporació: 23/09/08 Publicacions recents

compileInclude has no effect on load times. It will copy everything from the library you reference via compileInclude into the target bundle, but that doesn't change anything on the http level.

If you can go without it (and you can): You should. There are enough other solutions to the problem here.

Anji E, modificat fa 5 anys. Junior Member Apunts: 49 Data d'incorporació: 18/11/14 Publicacions recents

1. You can create a separate portlet (js-portlet)

2. Add Js logic 

3. Place the portlet on the same page. 

4. You can control displaying  of other portlets until js-portlet gets load by Liferay.portlet.ready() function in theme.

thumbnail
Olaf Kock, modificat fa 5 anys. Liferay Legend Apunts: 6441 Data d'incorporació: 23/09/08 Publicacions recents

You should build a Theme-Contributor, which can add JS resources (as well as CSS) without touching a theme.