cornerstone icon indicating copy to clipboard operation
cornerstone copied to clipboard

quick view load fast.

Open sumnima-studio opened this issue 1 year ago • 2 comments

is there any way to make quick view load fast. it's really really slow.

sumnima-studio avatar Jun 30 '24 11:06 sumnima-studio

I agree.

I tried to do some preloading for its content but the way it loads caused it to re-load it again.

My idea was to preload the view when the user hovers over the product card. So when they click the button, it is more likely that the content is already loaded.

I may try the idea again, but this time preload using fetch.

Tiggerito avatar Jun 30 '24 23:06 Tiggerito

No joy with using fetch. I presume it is designed not to cache. So I think a preload mechanism would need to be built in.

This is what I tried:

document.addEventListener('DOMContentLoaded', function() {
  document.querySelectorAll('.card').forEach(card => {
    card.addEventListener('mouseover', function() {
     
      var fetched = this.getAttribute('data-fetched');

      if (fetched) return;

      this.setAttribute('data-fetched', 'true');

      var productId = this.getAttribute('data-entity-id');

      var url = '/products.php?productId=' + productId;

      fetch(url, {
        credentials: "include",
        headers: {
          'stencil-config': '{}', 
          'stencil-options': '{"render_with":"products/quick-view"}', 
          'x-xsrf-token': BCData.csrf_token, 
          'x-requested-with': 'stencil-utils', 
          'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },
        method: "GET"
      })
        .then(response => response.text())
        .then(data => {
          console.log('Product data:', data);
        })
        .catch(error => {
          console.error('Error fetching product data:', error);
        });
    });
  });
});
</script>```

Tiggerito avatar Jul 01 '24 02:07 Tiggerito