Disable refresh delay for stylesheets when using inject and override remote CSS
When working on a remote server with a refresh delay and overriding CSS, it'd be great to not have any delay for stylesheet injection.
The issue is that while 80% of the use-case for the delay feature is working with an external server that's remote and requires an upload, there ARE other reasons to use the delay. Over the years, I've seen complex setups with certain CMSes that need a moment when files change, users working on network drives with latency, folks hosting their websites on a Synology NAS, etc.
So there ARE still cases where people would want the delay even when overriding remote CSS with a local copy.
As a workaround, I'd recommend this:
-
Turn off the delay. This will make sure your stylesheets are reloaded immediately after they finish compiling.
-
Add a Hook (codekitapp.com/help/hooks) that uses CodeKit's scripting API to issue a browser refresh command after X seconds. Assign this hook to run only when page-like files change (*.html, *.php, etc.)
When you save a page-like file, CodeKit will immediately reload the browsers once (but no changes will appear because the file hasn't finished uploading to your remote server yet). But the second refresh call from your Hook will get the job done. This essentially lets you apply the delay only when you need it.
Thanks for the explanation and workaround suggestion, I think that’ll work nicely for now 👍
The AppleScript to refresh works with the delay when executing from anywhere other than the CK hook, otherwise it fires right after the first refresh.
tell application "CodeKit"
refresh browsers by reloading the whole page after delay 5
end tell
Ha, of course it does. So the issue is that AppleScript must run on the main thread. If you do this:
delay 5
tell application "CodeKit"
refresh browsers by reloading the whole page
end tell
You'll get the delay you're after, but CodeKit will hang for 5 seconds because the main thread is tied up running the AppleScript command (which includes the delay). Apparently, 2012 Bryan was smart enough to recognize that a Hook calling the refresh command with the delay parameter would hang the UI, so the delay parameter is ignored there.
You may have better luck using the osascript -e command in a Bash script Hook. CodeKit executes bash Hooks on a background thread, so the UI should remain responsive, but you'll still likely see the "processing..." bar across the bottom of the app for five seconds because the Hook won't finish running until the delay completes.