Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

External JavaScript with session_id

Questions related to using nuBuilder Forte.
Post Reply
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

External JavaScript with session_id

Unread post 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?
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: External JavaScript with session_id

Unread post 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/
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: External JavaScript with session_id

Unread post by admin »

.
Post Reply