Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active November 11, 2024 03:14
Show Gist options
  • Select an option

  • Save sahal/62c8d77c2e41e58291876c304d5f4076 to your computer and use it in GitHub Desktop.

Select an option

Save sahal/62c8d77c2e41e58291876c304d5f4076 to your computer and use it in GitHub Desktop.
Tiddlywiki Revert to local copy of external JS

While browsing this page, How to reduce the size of your Tiddlywiki, I noticed that there were no instructions to revert back to a local copy in case of emergency. I can think of times where I might want to edit my tiddlywiki while offline but since I'm pointing to an external source, this could be a problem.

Normally, by overriding the coreURL variable inside the $:/core/save/offline-external-js ShadowTiddler you can set the external javascript file to be a remote site.

\define coreURL() http://your.domain.com/your-path/your-javascript-file.js

What happens when you try to load this and that external site is no longer available for whatever reason?

Well, like any good sysadmin, I backed up my TiddlyWiki core on your local machine. If not, take a look at the above help page and back it up now.

If you do happen to load the TiddlyWiki and you are offline, your external javascript will not load. You will get the following error:

Error: Cannot load http://your.domain.com/your-path/tiddlywikicore-5.3.5.js

Edit the html page to point to the local version using your favorite editor:

$ nvim index.html
. . .
<script src="http://your.domain.com/your-path/tiddlywikicore-5.3.5.js" onerror="alert('Error: Cannot load http://your.domain.com/your-path/tiddlywikicore-5.3.5.js');"></script>
</body>
</html>

Make sure to edit the $:/core/save/offline-external-js ShadowTiddler to remove references to a remote coreURL.

UPDATE

Almost as soon as I hit save on this, I realized I could work around this by keeping all my TiddlyWiki's in the same directory on both my local and remote servers. That way I could use the local copy when needed and the remote copy when remote without modifying the above ShadowTiddler.

Here's my directory structure for example:

(ins)sahal@shakuntala[~/tiddlers]$ ls -alh
total 27M
drwxr-xr-x  3 sahal sahal 4.0K Nov 10 21:13  .
drwx------ 48 sahal sahal 4.0K Nov 10 20:50  ..
drwxr-xr-x  2 sahal sahal 4.0K Nov 10 21:13  backups
-rw-r--r--  1 sahal sahal 138K Nov 10 21:05  book-notes.html
-rw-r--r--  1 sahal sahal 137K Nov 10 21:13  default-tiddly.html
-rw-r--r--  1 sahal sahal 2.3M Nov 10 20:30  tiddlywikicore-5.3.5.js
-rw-r--r--  1 sahal sahal 137K Nov 10 21:13  yerboi-journals.html


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment