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

quick view load fast. #2472

Open
sumnima-studio opened this issue Jun 30, 2024 · 2 comments
Open

quick view load fast. #2472

sumnima-studio opened this issue Jun 30, 2024 · 2 comments

Comments

@sumnima-studio
Copy link

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

@Tiggerito
Copy link
Contributor

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
Copy link
Contributor

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>```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants