Page 1 of 1

External JavaScript with session_id

Posted: Mon May 28, 2018 9:43 pm
by marc
Hi All,

I want to load an external JavaScript file and make sure it's not cached. When I update the external file, nuBuilder still loads the old file even when the user logs off and in again.
I thought I can work around that by adding the session_id to the javascript.

I've included an External JavaScript in the header :

Code: Select all

document.write('\x3Cscript type="text/javascript" src="https://apis.google.com/js/client.js?id=' + nuCurrentProperties().session_id + '">\x3C/script>');
but there's an error
Uncaught TypeError: Cannot read property 'session_id' of undefined
session_id is not defined when the header loads. Is there a better place to place it?

Re: External JavaScript with session_id

Posted: Sat Jun 02, 2018 12:28 pm
by toms
Try this (To be placed in Setup -> Header):

Code: Select all

$.getScript('https://apis.google.com/js/client.js', function() {});
By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested.
https://api.jquery.com/jquery.getscript/

Re: External JavaScript with session_id

Posted: Sun Jun 03, 2018 1:35 pm
by admin
.