vuestorefront / vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
https://www.alokai.com
MIT License
10.61k stars 2.08k forks source link

R&D: Create a PoC of offline-cache without indexedDb #2021

Closed pkarw closed 5 years ago

pkarw commented 5 years ago

What is the motivation for adding / enhancing this feature?

The indexedDB caching prooved to be a problematic solution because of:

  1. Currently, we're populating the cache in search.ts

This is PER-QUERY cache that we can replace with Service Worker cache. We can switch-off this logic in this PoC

IMPORTANT NOTE: Service Worker CAN NOT cache the POST requests - currently all the api/rest and graphql requests

We can easily modify the search adapter to send the GET requests + the searchQuery as a base64 encoded GET parameter instead of JSON body (check this) - and then modify the vue-storefront-api to unpack the GET-based search query and pass it to Elastic in correct format.

However, we CAN NOT add service worker caching for graphQL queries (read on graphQL supprt)

So - this service-worker only caching strategy should be disabled automatically when the search.engine=graphql and use the current indexed-db based cache as there won't by any offline mode otherwise.

The same in the situation when service-worker cache is not available at all

  1. Moreover, we're setting the cache of products by SKU (for having the product pages available even for products that user hasn't clicked; The cache is populated in the product/quickSearchByQuery

There is no network call for product data as we're using the product data pre-fetched in the product/list action

This cache won't be replaced by Service Worker. In fact - we probably need to keep this logic to avoid additional network-calls on product page (product/single vuex action) because of ...

  1. If You went to "Women" all products will be available even when offline because we do have a per-sku cache - which is used in product/single action)

The question is - how to keep this "pre-fetching" enabled without using the indexedDB? I mean per-sku cache. Service worker cache will work on full queries (product/list results).

Probably: we can store the per-sku cache (2) just in kind of in-memory hash - as the product/list action is always called first (as user is browsing first the category/search results - then selecting the product - so in product/list we can populate the memory cache allowing product/single to use it)

Our indexedDb driver is using the in-memory stores for speed optimization already

Notes:

What are the acceptance criteria

Can you complete this feature request by yourself?

Additional information

pkarw commented 5 years ago

@NataliaTepluhina could You please reframe this issue's description and put it into docs as kind of "How Offline Mode works" ?

pkarw commented 5 years ago

Any other ideas how to improve this - feel free to comment :)

filrak commented 5 years ago

Ill take it :)

pkarw commented 5 years ago

@filrak it seems like @patzick already took it :) we discussed it yesterday evening and he’s already investigating this issue

filrak commented 5 years ago

Haha no problem. Just please consult it with me. We should obviously use Workbox for this

filrak commented 5 years ago

And take this into account https://github.com/DivanteLtd/vue-storefront/issues/1994

pkarw commented 5 years ago

We need to consider this one as well: https://github.com/DivanteLtd/vue-storefront/issues/1698