diff --git a/editions/tw5.com/tiddlers/webserver/Using the external JavaScript template.tid b/editions/tw5.com/tiddlers/webserver/Using the external JavaScript template.tid index 75b5f1484..75d38cc29 100644 --- a/editions/tw5.com/tiddlers/webserver/Using the external JavaScript template.tid +++ b/editions/tw5.com/tiddlers/webserver/Using the external JavaScript template.tid @@ -1,5 +1,5 @@ created: 20180905075846391 -modified: 20230319130830880 +modified: 20240413045138914 tags: [[WebServer Guides]] title: Using the external JavaScript template type: text/vnd.tiddlywiki @@ -20,7 +20,7 @@ The remaining inefficiency when working in the client server configuration is th ! Using the external ~JavaScript template with the client-server configuration -The mechanism is activated by setting the [[root-tiddler|WebServer Parameter: root-tiddler]] parameter to `$:/core/save/all-external-js`. This template externalises ~TiddlyWiki's core ~JavaScript into a separate file. For example, the following command will start your server with caching enabled. It will transfer the wiki with two GET requests, and the core can be cached by the browser. +The mechanism is activated by setting the [[root-tiddler|WebServer Parameter: root-tiddler]] parameter to `$:/core/save/all-external-js`. This template externalises ~TiddlyWiki's core ~JavaScript into a separate file. For example, the following command will [[start your server with caching enabled|WebServer Parameter: use-browser-cache]]. It will transfer the wiki with two GET requests, and the core can be cached by the browser. ``` tiddlywiki YOUR_WIKI_FOLDER --listen 'root-tiddler=$:/core/save/all-external-js' use-browser-cache=yes diff --git a/editions/tw5.com/tiddlers/webserver/Using the integrated static file server.tid b/editions/tw5.com/tiddlers/webserver/Using the integrated static file server.tid index 515730a3b..91544551e 100644 --- a/editions/tw5.com/tiddlers/webserver/Using the integrated static file server.tid +++ b/editions/tw5.com/tiddlers/webserver/Using the integrated static file server.tid @@ -1,5 +1,5 @@ created: 20180703095630828 -modified: 20180703100445719 +modified: 20240413045124764 tags: [[WebServer Guides]] title: Using the integrated static file server type: text/vnd.tiddlywiki @@ -13,4 +13,19 @@ Static files can be referenced directly: * `[ext[./files/a-big-document.pdf]]` - to make a link to a PDF * `[img[./files/a-big-image.png]]` - to embed an image -Alternatively, the ''_canonical_uri'' field can be used to reference the files as [[external tiddlers|ExternalImages]]. \ No newline at end of file +Alternatively, the ''_canonical_uri'' field can be used to reference the files as [[external tiddlers|ExternalImages]]. + +If [[WebServer Parameter: use-browser-cache]] is used, these files will be cached by the client's browser to save on bandwidth. In this case, the `cache busting strategy` can be used to make sure the client always has the latest updated files. + + +<<< +https://javascript.plainenglish.io/what-is-cache-busting-55366b3ac022 + +!! Cache Busting + +There are a couple different ways of changing the names of files so that they will load when they change. One way is to use version numbers and have them somewhere in the file name when loading. You could have a subdirectory for every version, `v1/index.js` `v2/index.css` . You could also have the version in queries in the URLs, `index.js?v1` , `index.css?v2` . + +Another way is to change the name of the file, `index.v1.js` , `index.v2.css` . These ways are not as manageable because this can become very hard once you have a ton of files that are being changed. + +A more popular and manageable way is to keep hashes inside the file names. Hashes, if you don’t know, are fixed length character representations of any content and they are irreversible, meaning you can get the hash from the file but you can’t get the file from the hash. Hashes are perfect for this, because when a file changes its hash will change, so if we keep the hash inside the filename `index.[someHashHere].js` browsers will detect it and load it instead of an old file. +<<< diff --git a/editions/tw5.com/tiddlers/webserver/WebServer Parameter_ use-browse-cache.tid b/editions/tw5.com/tiddlers/webserver/WebServer Parameter_ use-browse-cache.tid new file mode 100644 index 000000000..2d0693aa2 --- /dev/null +++ b/editions/tw5.com/tiddlers/webserver/WebServer Parameter_ use-browse-cache.tid @@ -0,0 +1,25 @@ +caption: use-browse-cache +created: 20240413042652008 +modified: 20240413050841387 +tags: [[WebServer Parameters]] +title: WebServer Parameter: use-browser-cache +type: text/vnd.tiddlywiki + +The [[web server configuration parameter|WebServer Parameters]] ''use-browser-cache=yes'' activates 200 OK browser caching via the `Cache-Control` header and a smart a Etag header: + +* The server javascript creates an MD5 `hash` object. +* Adds the data of the current `request:response` (for example: json text or an image binary) to the hash object. +* Adds the current `headers` of the response to the hash object. +* If the response data has an `encoding` value, adds the encoding to the hash object. +* Calculates the final MD5 hash string as a `contentDigest` javascript variable, and saves it as an `Etag: "<>"` header. + +If the incoming request contains a header named `if-none-match`, then the server will check the generated Etag against all values. + +If any `if-none-match` value DOES match the current Etag, the server will send a `304 NOT MODIFIED` response with the current response headers, instead of the data with a `200 OK` response. + +This saves bandwidth, as the client can be sure they have already received the exact data and has it in their current cache. + +If ''use-browser-cache=no'' (or any other value including null), then the server will return a `Cache-Control: no-store` header by default. + +If any customer server route module defines custom `Cache-Control` header behavior, then the server will pass that header through instead of the default. + diff --git a/editions/tw5.com/tiddlers/webserver/WebServer.tid b/editions/tw5.com/tiddlers/webserver/WebServer.tid index c1ab5ae2a..afa3fe749 100644 --- a/editions/tw5.com/tiddlers/webserver/WebServer.tid +++ b/editions/tw5.com/tiddlers/webserver/WebServer.tid @@ -1,5 +1,5 @@ created: 20180626150526207 -modified: 20181216181934282 +modified: 20240413043741157 tags: ListenCommand ServerCommand Features title: WebServer type: text/vnd.tiddlywiki