Custom HTML Prompt not reloading changed CSS/JS files?

@peternlewis - Is it possible that the Custom HTML Prompt action doesn’t reload .js and/or .css files that were modified since the last run? It sure looks like it to me.

If this is by design, can you tell me how to work around this while testing? Thanks.

It’s not something I do directly, but yes it appears webkit is a little overzealous about caching.

You can reload the page by control clicking and selecting Reload.

1 Like

I fixed this by adding window.location.reload(); to the KMWillShowWindow() function. At least this fixed it for me with a .jpg file I was updating between runs of bringing up the prompt. Not sure it’ll work with CSS and JS resources specified in the <HEAD> section of a page.

function KMWillShowWindow() { window.location.reload(); }

1 Like

Gah, after playing with this I found doing this prevents you from using
document.getElementById(‘test’).innerHTML = window.KeyboardMaestro.ProcessTokens(’%Variable%test%’);

when the reload triggers all the HTML set reverts to the un-replaced version.

This happens if I put the reload in KMInit, KMWillShowWindow or KMDidShowWindow. Also putting the above javascript in any of those versions (i.e. reload in Init and set the html in KMDidShowWindow) doesn’t work either, even though you’d think KMInit would run before KMDidShowWindow.

since i’m doing this with a jpg file i’m just going to have a different filename generated each time and have the macro delete it at window close.

The only ways I know for sure to fix this are:

  1. Include the CSS and JS inside the HTML file. Obviously you only need to do this for the CSS and JS files you’ll be changing.
    -or-
  2. Restart the KM Engine each time you modify one of the CSS or JS files.

For me, with some of my projects, I keep the CSS and JS files separate, and I use a custom preprocessor I wrote to combine the files into a single HTML file while I’m testing. Not ideal, but it works pretty well, especially since I automate running the preprocessor using KM. :slight_smile:

Here’s another thing I sometimes do: I use Atom to edit the HTML, CSS and JS files, and Atom supports code folding. So sometimes I keep everything in one big HTML file, and use code folding to hide things I’m not working on. If you decide to do this, let me know, because I’ve got some tricks.