Skip to content
I001962 edited this page Jul 24, 2021 · 5 revisions

UNDER CONSTRUCTION - Experimentation and conversation captured here.

The Idea

Have webpages access a cached version of Gun data from the CDN the site is deployed to. The goal is faster first paint time then going through network and getting updates.

Possible solution

Assuming JAM Stack app has a build step we could have Gun added to the project eg a Gatsbyjs site we

  1. npm install gun
  2. in a postBuild step have gun.get('yourdata').get('for first paint).once()
  3. then move the node_modules/gun/radata folder to the public folder created by gatsby build.
  4. Gatsby in this case deploys the content of the public folder to a cnd.

The pages that require gun data would then pull in the precached version of the data in gun. Note this data is frozen once deployed to the CDN. Here is some sample code that tells RAD to get from the CDN instead of eg browser localStorage:

var Rad = window.Radisk; // in Browser, still needs rad related scripts. See [RAD docs] (https://gun.eco/docs/RAD)
var opt = {store: {}, file:'https://yourfavoritecdn.com/yoursite/radata/'}; // cdn location
opt.store.put = function(key, data, cb){
  localStorage[''+key] = data;
  cb(null, 1);
} // important! not going to put any data but must be defined. 
opt.store.get = async function(file, cb){
    cb( null, await (await fetch(opt.file + file)).text())};
// need better way but works for now.
var rad = Rad(opt);
rad('KMAC', function(err, data){ console.log(data) }) // get rad tree. see [RAD docs] (https://gun.eco/docs/RAD)
  1. ideally we have RAD data already loaded before RAD code runs, which should be faster than
  2. this which loads RAD async upon 1st query, which should be faster than
  3. loading data by first connecting into the network and then getting updates. (this will happen even if 1 or 2 occur)

This wiki is where all the GUN website documentation comes from.

You can read it here or on the website, but the website has some special features like rendering some markdown extensions to create interactive coding tutorials.

Please feel free to improve the docs itself, we need contributions!

Clone this wiki locally