Sharepoint online navigation caching?

New Contributor

I am using Aplication Customizer to add jQuery and custom javascript to my page:

let current_date: Date = new Date();
let date_String: string = current_date.toString();
date_String = current_date.toISOString()
console.log('date_string = %s', date_String);
SPComponentLoader.loadCss('https://8lbg15.sharepoint.com/sites/KnowledgeBase/SiteAssets/caj23.css?d=' + date_String);
//SPComponentLoader.loadScript('https://8lbg15.sharepoint.com/sites/KnowledgeBase/SiteAssets/jquery-3.6.3.min.js?d=' + date_String)
//SPComponentLoader.loadScript('https://8lbg15.sharepoint.com/sites/KnowledgeBase/SiteAssets/caj23.js?d=' + date_String);

SPComponentLoader.loadScript('https://8lbg15.sharepoint.com/sites/KnowledgeBase/SiteAssets/jquery-3.6.3.min.js?d=' + date_String, {
globalExportsName: 'jQuery'
}).then(($: any) => {
$(function () {
console.log('jQuery is loaded');
});
SPComponentLoader.loadScript('https://8lbg15.sharepoint.com/sites/KnowledgeBase/SiteAssets/caj23.js?d=' + date_String, {}).then(() => {
//...do something
});
});


The code runs fine when I open the page. However, if I navigate to the page from the main site navigation (ie the mega menu) the code doesn't run. Yet if I click on the link a second time in the nav, it loads the page and the code runs.

In other words, it doesn't rung when you change pages via the nav, but if you load the same page (or reload the page with F5) it does!!!

Is this some kind of caching issue? I am using Sharepoint Modern/Online so there is no caching setting for the site.

Any solutions gratefully received.

 

1 Reply
Seems to be a routing interceptor that will check your link and if appropriate, do a partial navigation, ie avoiding a full page load.

To work around and force javascript to run, add
data-interception="off"
to all links eg by script

$('a').attr("data-interception", "off");