CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   '$.getScript()' question! (http://www.codingforums.com/showthread.php?t=274533)

ECoode 09-28-2012 09:07 AM

'$.getScript()' question!
 
Hey CodingForums and coders!
I'm coding plugin for a website and websites has good APIS to example check when someone joins to chat and to send automatically message: 'Welcome' etc.

So I'm coding /update command to my 'chatbot' and was goin to use $.getScript to get newest, updated script from url and run it again / replacing old code.

So everytime when I send to chat '/update' chatbot will run function update.
What do I need to do to replace the old code with the new code?

Here's something what I tried and I think it's working, or is it?
Code:

$.getScript(url,function(){
        // Sends message 'chabot is updated' and get's version from variable chatBotV!
});

Also nice add would be to check if olds code version (variable chatBotV) is same as updated, it wont replace it.
If you need more details comment below...
~Thanks, ECode

ECoode 09-28-2012 11:22 AM

I'm sure someone could help me out even a bit!
*BUMP*!

Philip M 09-28-2012 11:59 AM

Quote:

Originally Posted by ECoode (Post 1274413)
I'm sure someone could help me out even a bit!
*BUMP*!

We are not some sort of public utility standing around here 24/7 just waiting for your questions. Please have a look at forum Guideline #5

5) Do not bump your thread repeatedly when you don't get a response. Sometimes when you post for help, you may not get a response in a timely matter, if at all. Forums aren't wishing wells, and some questions will fall through the cracks. That's a fact of life. It's ok to occasionally bump a thread, but only when done after an ample amount of time (ie: 2-3 days) have passed without a response, and never more than once. Your thread is no more important than another member's when it comes to the amount of attention it should receive.

ECoode 09-28-2012 03:47 PM

Ok I'm trying to re-post this to other forums if one of them could answer :)

ECoode 10-03-2012 08:08 AM

Couple days since no1 answered!
So now I can *bump* *bump* it !

felgall 10-03-2012 11:20 PM

If you just want to force the script to download when they first access the page rather than using a cached copy then just add a querystring on the end of the src attribute of the script tag with a value that is always changing (the easiest way is to use server side code to insert the date/time).


To replace a JavaScript with the latest version dynamically at regular intervals while they are still on the page you just need to run the appropriate DOM commands to replace the script tag in the page and add a different value in the querystring so that it forces it to redownload the script rather than usung the cached copy.

for eexample the following will reload script.js from the server every five minutes (you just need to add id="js" to the script tag so it knows which tag to replace)

Code:

setInterval(
  function() {var d, s;
      d = document.getElementById('js');
      s = document.createElement('script');
      s.src = 'myscript.js?d='+ Date.now();
      s.id = 'js';
      d.parentNode.replaceChild(s,d);
      },
  300000);


ECoode 10-04-2012 02:48 PM

Quote:

Originally Posted by felgall (Post 1276033)
If you just want to force the script to download when they first access the page rather than using a cached copy then just add a querystring on the end of the src attribute of the script tag with a value that is always changing (the easiest way is to use server side code to insert the date/time).


To replace a JavaScript with the latest version dynamically at regular intervals while they are still on the page you just need to run the appropriate DOM commands to replace the script tag in the page and add a different value in the querystring so that it forces it to redownload the script rather than usung the cached copy.

for eexample the following will reload script.js from the server every five minutes (you just need to add id="js" to the script tag so it knows which tag to replace)

Code:

setInterval(
  function() {var d, s;
      d = document.getElementById('js');
      s = document.createElement('script');
      s.src = 'myscript.js?d='+ Date.now();
      s.id = 'js';
      d.parentNode.replaceChild(s,d);
      },
  300000);


Thanks for this very useful information!
I really appreciate that you answered, thanks again :D!


All times are GMT +1. The time now is 12:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.