Considering that for most sites the user won't have any matching script, it would be interesting to be able to quickly return from the extension instead of hitting the file system looking for scripts that don't exist. For instance, say the user loads gist.github.com on their browser. Witchcraft would then be triggered and the follow would happen:
foreground script sends request to background script
background script propagates the request to the local server
local server parses the hostname and collects list of files to look for
ask the file system for ~/.witchcraft/com.css
ask the file system for ~/.witchcraft/github.com.css
ask the file system for ~/.witchcraft/gist.github.com.css
ask the file system for ~/.witchcraft/com.js
ask the file system for ~/.witchcraft/github.com.js
ask the file system for ~/.witchcraft/gist.github.com.js
return response to the background script
call back foreground script with the response
We'd then hit the file system 6 times for a single page load. This happens to each and every page loaded by the browser and it gets worse if you consider that several pages also load iframes as well.
So that's why it would be good to have an in-memory set of all script names that exist under ~/.witchcraft, even if we don't keep the scripts themselves in memory, since it would immensely help pages that don't have any script to be loaded. We could just look for candidate scripts in the set and, if none is found, just return immediately.
Considering that for most sites the user won't have any matching script, it would be interesting to be able to quickly return from the extension instead of hitting the file system looking for scripts that don't exist. For instance, say the user loads
gist.github.com
on their browser. Witchcraft would then be triggered and the follow would happen:~/.witchcraft/com.css
~/.witchcraft/github.com.css
~/.witchcraft/gist.github.com.css
~/.witchcraft/com.js
~/.witchcraft/github.com.js
~/.witchcraft/gist.github.com.js
We'd then hit the file system 6 times for a single page load. This happens to each and every page loaded by the browser and it gets worse if you consider that several pages also load iframes as well.
So that's why it would be good to have an in-memory set of all script names that exist under
~/.witchcraft
, even if we don't keep the scripts themselves in memory, since it would immensely help pages that don't have any script to be loaded. We could just look for candidate scripts in the set and, if none is found, just return immediately.