dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.18k stars 3.31k forks source link

umd version, doesn't work without connection #2041

Closed JoranTab closed 1 year ago

JoranTab commented 1 year ago

I'm using Photoswipe on a local website for an interactive kiosk that won't be connected to the Internet. I use the umb version (I have ajax navigation and can't do anything else). I have both js locally (photoswipe.umd.min.js and photoswipe-lightbox.umd.min.js). Everything works fine when I'm connected to the Internet, but as soon as I disconnect the computer, photoswipe no longer launches. Any ideas?

dimsemenov commented 1 year ago

Can you show the source of your HTML page, please?

JoranTab commented 1 year ago

To make sure this isn't another problem with my site, I ran a test with the simple code you suggest, but with local images. I tested it by putting it on my local server or on a normal folder and I'm having the same problem.
Lightbox work when It's connected to Internet. As soon I disconnected, lightbox doesn't work anymore, even if I didn't reload the page...

Here is the code :

<!DOCTYPE html>
<html>
  <head>
    <title>Test Gallery</title>
  </head>
  <body>

    <script src="./photoswipe.umd.min.js"></script>
    <script src="./photoswipe-lightbox.umd.min.js"></script>

    <link rel="stylesheet" href="./photoswipe.css">

    <div class="test-gallery">
      <a href="./img-big.jpg" data-pswp-width="588" data-pswp-height="800">
        <img src="./img-small.jpg" alt="" />
      </a>

    </div>

    <script type="text/javascript">
      var lightbox = new PhotoSwipeLightbox({
        gallery: '.test-gallery',
        children: 'a',
        // dynamic import is not supported in UMD version
        pswpModule: PhotoSwipe 
      });
      lightbox.init();
    </script>

  </body>
</html>
dimsemenov commented 1 year ago

I'm not sure, what do you have in Console and any failed requests in Network?

JoranTab commented 1 year ago

There is nothing in console, no failed requests. Image only open in new tab. I checked network request when the computer is connected and photoswipe works, there is only request on local... I have the same behavior on two different computers and with firefox or chrome.

This is a slightly different case, but if I went to https://photoswipe.com/getting-started/, I open an image to have everything in cache. If i disconnected internet and click on the image, photoswipe doesn't work anymore. On examples of documentation V4, it doesn't happen. I load everything, click on a image then disconnect internet and photoswipe continues to work.

By the way, thank you very much for Photoswipe, I've been using it for several years and it really is the best lightbox system !

dimsemenov commented 1 year ago

It might be because of window.navigator.onLine detection here https://github.com/dimsemenov/PhotoSwipe/blob/master/src/js/lightbox/lightbox.js#LL81C12-L81C35

I wonder if there should be an option to disable this feature detection or if it should be removed entirely.

JoranTab commented 1 year ago

It works when I remove this condition. Thanks !