Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: LR 7.1 SPA portlet - avoid script reload
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
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
Powered by Liferay™