Sharepoint online navigation caching?

Copper 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('' + date_String);
//SPComponentLoader.loadScript('' + date_String)
//SPComponentLoader.loadScript('' + date_String);

SPComponentLoader.loadScript('' + date_String, {
globalExportsName: 'jQuery'
}).then(($: any) => {
$(function () {
console.log('jQuery is loaded');
SPComponentLoader.loadScript('' + date_String, {}).then(() => {
// 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.


2 Replies
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
to all links eg by script

$('a').attr("data-interception", "off");
Thank you so much!