react-with-moxy
react-with-moxy copied to clipboard
Add peer-to-peer loading capabilities
Using the IPFS ServiceWorker gateway, we could accelerate the website, and make it peer-enabled. This would be very interesting for all the reasons why IPFS exists, namely:
- accelerate load time on flaky connections, especially when there are peers nearby that have accessed the same website.
- sharing the load on peak moments, the more people demanding resources, the more people contributing.
This could be achieved by creating a webpack plugin that would generate the hashes for all assets within the build, much like cache-busting strategies, so the assets within the page would be addressed using an ipfs path, which could either go to the server, or be caught by the ServiceWorker, and served from a peer.
@vasco-santos @satazor, you guys might want to share your thoughts here.
The idea would be to build the website, and the resulting asset addressing would be something like:
// ...
<img src="/ipfs/<file CID>.<file extension>" />
// ...
The service worker would ignore the extension, but when fetching from server, we would fetch with the extension, so that the file is served with the right mimetype.
On build, we can put all assets under an /ipfs folder, and all files under it are using this strategy.
Identifying what needs to be done:
- Upon build, add files to IPFS, and map their filenames to their CID.
- We could just generate the CID, but not actually
addto a node upon build, to make it simpler for now.- Later, it would probably make sense to add something on the
deploycommand, that would also add/pin the files.
- Later, it would probably make sense to add something on the
- Should have a configuration for maximum filesize here, and any file above this size falls on the server.
- Would be nice to have an
ignoreconfiguration, so that certain files could be skipped, and only use server. - Should have a configuration for the TTL, on client
get.
- We could just generate the CID, but not actually
- Include code that bootstraps an IPFS ServiceWorker Gateway in the build.
- Code should intercept any requests to
/ipfs/*and try to load them from IPFS first, and fallback to server if not available. - Upon loading, client should
addthe files, so it can also host for other peers.
- Code should intercept any requests to
@hugomrdias is already doing the hashing on build part.
I suggest that @vasco-santos takes care of interception+fallback to HTTP + add after load, and @fsdiogo takes care of preparing the plugin to add @vasco-santos' code on build to the bundle.
/cc @diasdavid you might want to look into what we're trying to build here, to make this part of our boilerplate for webapps, enabling them to load static assets from IPFS first.