Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external images in client-server configuration #1000

Open
Jermolene opened this issue Oct 21, 2014 · 11 comments
Open

Support external images in client-server configuration #1000

Jermolene opened this issue Oct 21, 2014 · 11 comments

Comments

@Jermolene
Copy link
Member

TiddlyWiki draws a distinction between lazily loaded images and external images:

  • Lazily loaded images are delivered in the initial HTML file with their text missing, which is then loaded on demand if and when the image is displayed. When it is loaded it becomes an ordinary tiddler, with the body stored in JavaScript memory. See http://tiddlywiki.com/#:LazyLoadingMechanism%20LazyLoading
  • Externally loaded images are delivered in the initial HTML file with their text missing and with a _canonical_uri field that gives the URI of the image. This URI is used directly in HTML img tags, without ever loading the body of the image as a tiddler. See http://tiddlywiki.com/#ExternalImages:ExternalImages

Both types can be used with the standalone configuration, but currently only lazily loaded images are supported in the client-server configuration (see the script ./bin/lazy.sh). The disadvantage of lazily loaded images is that they still consume JavaScript memory and they are rendered as inline base64 images which are not as performant as images retrieved via HTTP.

The following changes are needed in order to support external images in the client-server configuration:

  • Extend server.js with simple content negotiation when retrieving tiddlers, enabling it to serve either the current JSON format or the raw resource depending upon what the browser asks for with the "Accept" header
  • Insert the variable transclusion <<customSaveTiddlers>> just before the first closing </div> in $:/core/templates/store.area.template.html
  • Create a new save filter based on $:/core/save/lazy-images that sets customSaveTiddlers to a rendering of the current image tiddlers with the text field omitted and the _canonical_uri field added. The latter would be set to recipes/default/tiddlers/<encodedimagetitle>
@jayfresh
Copy link
Contributor

jayfresh commented Nov 6, 2014

bonus for your 1000'th issue! 👍

@Jermolene
Copy link
Member Author

@jayfresh thanks, makes me feel old!

@danielo515
Copy link
Contributor

So those images will be loaded when you open that tiddler? Like in normal Web page navigation?

@Jermolene
Copy link
Member Author

So those images will be loaded when you open that tiddler? Like in normal Web page navigation?

Yes, that's right; in the browser we'd have an ordinary <img> tag with the URL pointing to the image on the server.

@rubaboo
Copy link
Contributor

rubaboo commented Jul 14, 2016

@sukima
Copy link
Contributor

sukima commented Jul 22, 2016

PR #2502 introduces a static file server module which in theory would fix the relative path problem described in this issue. Just wanted to link the two discussions.

@gw
Copy link

gw commented Dec 3, 2019

Curious about the latest state of this. I run TW5 in standard client-server mode on a VPS and my content's very image-heavy. Would love for the drag-and-drop importer to upload my images to my VPS and create skinny _canonical_uri tiddlers for me.

Happy to take a stab at this if you point me in the right direction.

@linonetwo
Copy link
Contributor

linonetwo commented Oct 20, 2023

I'm going to do this, currently my nodejs cost 2GB of ram to store images (After importing Evernote and clipping many websites).

The following changes are needed

I will follow your instruction. But those only ask client to load images in the _canonical_uri way. We may need extra modifications to ask server not load binary files' text field into memory at all.

@linonetwo
Copy link
Contributor

@gw That is not we are talking about in this issue. This issue is about automatically add _canonical_uri to image tiddlers "on loading", not "on saving". If you want the later one, you need to use the-file-uploads-plugin

@linonetwo
Copy link
Contributor

Also make sure tiddler with _canonical_uri is using sync-adaptor method to load, not using HTTP directly, because content may store in a SQLite, or has to be loaded via IPC/RPC method that is only accessible in sync-adaptor.


Not necessarily, just use a relative URL, and we can catch the URL call in Electron/React-Native to redirect them to the IPC call.

@pmario
Copy link
Member

pmario commented Oct 20, 2023

Also make sure tiddler with _canonical_uri is using sync-adaptor method to load, not using HTTP directly,

This behaviour can not be changed for backwards compatibility reasons. There are configurations, that depend on this behaviour

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

No branches or pull requests

8 participants