Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload JavaScript files without refreshing HTML

Tags:

I've a HTML which loads several Javascript files:

<script src="assets/js/a.js"></script> <script src="assets/js/b.js"></script> <script src="assets/js/jquery.min.js"></script> 

As I debug/test my Javascripts in my browser's console, is it possible to reload these Javascript files without the need to reload the entire HTML page?

like image 894
tommi Avatar asked Jun 03 '12 06:06

tommi


People also ask

How do I change the content of a page without reloading it?

AJAX = Asynchronous JavaScript and XML. AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

Can I reload JavaScript?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

How do you refresh a script in HTML?

In JavaScript, you refresh the page using document. location. reload() . You can add the true keyword to force the reloaded page to come from the server (instead of cache).

How can we refresh a DIV without reloading the whole page?

Use this. $('#mydiv'). load(document. URL + ' #mydiv');


1 Answers

You could remove and then re-add them:

$('script').each(function() {     if ($(this).attr('src') !== 'assets/js/jquery.min.js') {         var old_src = $(this).attr('src');         $(this).attr('src', '');         setTimeout(function(){ $(this).attr('src', old_src + '?'+new Date()); }, 250);     } }); 
like image 188
PitaJ Avatar answered Oct 21 '22 08:10

PitaJ