“live-reloading” web pages via AutoIt

So I've been recently looking for something to help with micro-debugging (mostly verifying output) of my JavaScript+HTML applications via automatically reloading test page on source change, and found a variety of solutions,

A bit of a trouble, isn't it? For most purposes, it'd suffice to check for file time change and refresh the page in the browser. So might as well do that with help of AutoIt.

It doesn't take much to accomplish the effect:

$time1 = ""
While 1
	$time0 = $time1
	$time1 = fileGetTime("C:/Temp/NewProject/bin/NewProject.js", 0, 1)
	if ($time1 <> "") and ($time0 <> $time1) then
		consoleWrite("Update: " & $time1 & @CRLF)
		$p = winGetHandle("[ACTIVE]") ; get current active window
		controlSend("New Project - Google Chrome", _ ; window title
			"", "", _ ; component
			"^r")
		winActivate($p) ; switch back to current active window
	endif
	sleep(500)
wend

How to use it:

  • Open your desired JS+HTML application in a (preferably separate) browser window
  • Enter window title text into code (you can guess where it goes by a comment saying "window title")
  • Enter "changing" file's location into code (if you are working on game, it's probably the main .js file)
  • Run the script (F5 if you are using the customized SciTE that comes with AutoIt)
  • Now, whenever the file is modified, script will refresh the browser tab, ensuring that it is of current version.
  • Once done with it, terminate the script (either via SciTE, or by adding a exit hotkey to code)

If you require watching multiple files, you can modify this to have multiple time-variables or an array of paths+times.

Related posts:

2 thoughts on ““live-reloading” web pages via AutoIt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.