Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2012, 09:07 AM   PM User | #1
ECoode
New Coder

 
Join Date: Aug 2012
Location: Finland
Posts: 23
Thanks: 2
Thanked 5 Times in 5 Posts
ECoode is an unknown quantity at this point
Smile '$.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 is offline   Reply With Quote
Old 09-28-2012, 11:22 AM   PM User | #2
ECoode
New Coder

 
Join Date: Aug 2012
Location: Finland
Posts: 23
Thanks: 2
Thanked 5 Times in 5 Posts
ECoode is an unknown quantity at this point
I'm sure someone could help me out even a bit!
*BUMP*!
ECoode is offline   Reply With Quote
Old 09-28-2012, 11:59 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by ECoode View Post
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 09-28-2012, 03:47 PM   PM User | #4
ECoode
New Coder

 
Join Date: Aug 2012
Location: Finland
Posts: 23
Thanks: 2
Thanked 5 Times in 5 Posts
ECoode is an unknown quantity at this point
Ok I'm trying to re-post this to other forums if one of them could answer
ECoode is offline   Reply With Quote
Old 10-03-2012, 08:08 AM   PM User | #5
ECoode
New Coder

 
Join Date: Aug 2012
Location: Finland
Posts: 23
Thanks: 2
Thanked 5 Times in 5 Posts
ECoode is an unknown quantity at this point
Couple days since no1 answered!
So now I can *bump* *bump* it !
ECoode is offline   Reply With Quote
Old 10-03-2012, 11:20 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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);
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
ECoode (10-04-2012)
Old 10-04-2012, 02:48 PM   PM User | #7
ECoode
New Coder

 
Join Date: Aug 2012
Location: Finland
Posts: 23
Thanks: 2
Thanked 5 Times in 5 Posts
ECoode is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
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 !
ECoode is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 PM.


Advertisement
Log in to turn off these ads.