Global data across the website #7079
Replies: 2 comments 7 replies
-
Some clarifications would be helpful:
I think removing dependency on runtime environment variables where possible and thus moving more towards static (incremental or otherwise) generation would be a good thing. Unfortunately this does mean that there would likely be a point where we'd need a different image for stage and prod, which (at least for me) we would need a very strong justification for. I lean more towards wanting to solve this with caching etc, because it gives us the flexibility to add/change data without needing to think up new solutions. On the other hand, I don't think we should shy away from adding async calls to pages, so perhaps a combination of the approaches where we choose based on performance and network payload would work well. |
Beta Was this translation helpful? Give feedback.
-
@wellcomecollection/js-ts-reviewers I have an example repo here This is mainly exploring the file system route as I couldn't get past even sharing the data with other methods. The main restriction with the file system route is that it uses
-- Source We might be able to use those values from the data fetching methods and create a cache that is more accessible. import fileStore from './fsStore'
import accessyCache from './accessyCache'
function getServerSideProps() {
const toggles = fileStore.get('toggles')
// this could use memory style cache as we're now in the context of the next app
const accessyCache.set('toggles')
} My suggestion would be that we implement the current fs cache. We could continue to use Contexts, but hoised to the the If we wanted to remove those contexts - we could look at something similar to ☝️ |
Beta Was this translation helpful? Give feedback.
-
What's the problem
We need data across the site that is dynamic and generally fetched asyncronously.
These are
I see two approaches
Cache data
Create another cache
There are quite a few options outlined in this discussion,
before exploring any, I would like to get a taste for how people feel about solving these individually vs globally hereand we should explore them.Setting the requirements of this:
1 & 2 - creating and accessing the data
An example of how to do this.
Something like
next-plugin-preval
is nice, but maybe adds overhead that we might not want.There is the more more rudimentary webpack val-loader - usage explained here.
A nicer interface for something like ☝️ is hashicorp's
prebuild-webpack-plugin
.The next step using any of the above is fiddly. How do we update the data incrementally?
Updating the data incrementally?
Write and update a file cache on an interval
Have an API endpoint that updates the data... this has many issues, one being you might only update the content one 1 instance / lambda etc, so ruling this out.
Incremental static regeneration
We could use . While this might work well for things like stories, and landing pages, and I think we should implement this here, it won't work well for things like search.
As this needs to be a global solution, this doesn't work.
Look at them individually
Opening times
???
Global alert
This could be async and built accessably.
Thoughts
Global popup
This could be async and built accessably.
Thoughts
Toggles
We could just bake the toggles into the app.
Thoughts
While the intention of the toggles livining in a different place was to be able to enable / disable them outside of deployment from a separate source, currently S3, this is never how we really do it.
The reason for this was the process of:
default: on
for everyonedefault: off
to stop broken serviceIt can also be useful for features that might degrade performance outside of our control, e.g. analytics code, sign ups, surveys, etc.
If we deem that this functionality is not required, we could bake them in.
Personally I think it's worth trying to finish this feature (it's has some holes in it) and improve it to make it more accessible, as I think that's the reason we don't use it.
Prismic
Currently we store a cached version of a JS object with methods you can call. This is an issue as it's not really data.
The issue however that we try to solve is that Prismic does two calls when looking up a document:
getApi
does an async call to get the current version, orref
, of the documents.getDocument
(or similarGET
s) with theref
fetched above to fetch that version of the document.While I think caching of the object should not be included in this discussion, caching the ref could be.
Beta Was this translation helpful? Give feedback.
All reactions