Message Boards

shared js files in different portlet project

Hairi Lani, modified 3 Years ago.

shared js files in different portlet project

New Member Posts: 17 Join Date: 4/9/20 Recent Posts

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, modified 3 Years ago.

RE: shared js files in different portlet project

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

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, modified 2 Years ago.

RE: RE: shared js files in different portlet project

New Member Posts: 17 Join Date: 4/9/20 Recent Posts

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, modified 2 Years ago.

RE: RE: shared js files in different portlet project

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

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, modified 3 Years ago.

RE: shared js files in different portlet project

Junior Member Posts: 49 Join Date: 11/18/14 Recent Posts

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, modified 3 Years ago.

RE: shared js files in different portlet project

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

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