RE: LR 7.1 SPA portlet - avoid script reload

Chris Friedl, modified 6 Years ago. New Member Posts: 11 Join Date: 3/1/18 Recent Posts

Hi,

 

I have a custom portlet - using javascript - embedded in the footer of my LR theme.

 

When SPA is enabled, everytime I navigate to a page in LR, the whole DOM is thrown away and built again - including the loading of my included JS files.. This causes me trouble because I am using "const" fields. When navigation is done, the JS files are loaded and want to create the "const" fields again -> this results in an error because the old const was not removed before. Only the DOM ist built newly - not the JS context.

 

According to the LR documentation there is a senna.js attribute which should avoid the reloading of JS resources:

<script src="myscript.js" data-senna-track="permanent" />

Unfortunately, this does not work at all on my LR Portal. The resources marked with the attribute above still get loaded again. 

I include my JS resources in the view.jsp of my portlet.

As I mentioned before: the portlet is embedded in the footer of my theme.

 

Has anyone experience with preventing loading JS on navigation?

The use of "const" is not my only concern ... there are other problems also which come with multiple loading of my used JS libraries. 

 

Thank you

Chris

thumbnail
Charalampos Chrysikopoulos, modified 6 Years ago. Junior Member Posts: 79 Join Date: 12/9/11 Recent Posts
Hi, I have seen the same problem. We have a portlet (that is migrated from 6.2) and it has a js include in its liferay-portlet.xml. The portlet is placed on a page and it works well.If we reload the page from the browser, then everything stays ok.
But, if we load the same page from the navigation menu, then the same js resource seems to be load two times. This can be proven, by opening the network tab in the browser inspector and search for the js file.Every load we make from the navigation (which doesn't trigger a page reload) adds a new instance of the js resource in the page. This problem disappears if we deactivate senna.js from the portal. By adding <single-page-application>false</single-page-application> in the liferay-portlet.xml the problem isn't solved.If anybody has an idea, place share it with us.Thanks in advance,Harry