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

reduce duplicate fetches for cache.json by storing in client.js memory #347

Open
1 of 5 tasks
thescientist13 opened this issue May 7, 2020 · 4 comments
Open
1 of 5 tasks
Assignees
Labels
Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) good first issue Good for newcomers
Milestone

Comments

@thescientist13
Copy link
Member

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

As a minor optimization for client.js, it would be good to cache in memory previously fetched calls to cache.json.

Details

In this way, the browser won't have to make redundant HTTP requests to something it already has access to.

@hutchgrant
Copy link
Member

You cannot cache them in client.js because it's not a singleton. A new instance is created every single route change, for each component that imports it.

@hutchgrant
Copy link
Member

hutchgrant commented May 13, 2020

We can however reuse the <script data-state="apollo"></script> to hold our window.__APOLLO_STATE__ data. On route change currently, that data remains static from when the page was initially loaded(even that isn't being utlized at all). Could also utilize localstorage in the browser.

Modify client.js like so:

client.query = (params) => {

  if (APOLLO_STATE && Object.keys(APOLLO_STATE).length === 0) {

and it will use the apollo_state on initial page load. The problem is when the route changes, with this condition it will try to reach graphql server.

@thescientist13
Copy link
Member Author

thescientist13 commented May 16, 2020

Basically if we provide client side routing of any kind (SPA / hybrid model), then we should expect to have to reload the whole page (app shell) if we want things to work as would expect in SSG mode (which would be doing a full page reload)

Part of paying the cost to enable going beyond just progressive enhancement. But makes things simpler for at least achieve SSG mode. 😄

@thescientist13
Copy link
Member Author

Moving to deferred for this project to be added to our next project, but it looks we can take advantage of the work being deon for adding an MPA setting in #477 to implement what we need for this feature.

More info here - #487 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) good first issue Good for newcomers
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants