Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-24839

The image lightbox is loaded on every page view, even on pages without any image

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 14.1-rc-1
    • Image - Lightbox
    • Unknown

    Description

      Reproduction steps

      1. Visit a page that contains no image, for instance http://localhost:8080/xwiki/bin/view/Sandbox/
      2. Open the browser debugger and make sure "disable cache" is checked
      3. Reload the page and look at the network tab

      Expected

      The image lightbox code is not loaded, since there is no image on the page to open in a lightbox. In particular moment-timezone-with-data.min.js is not downloaded.

      Actual

      About 821 KB of JavaScript and CSS are downloaded on every page view:

      • moment-timezone-with-data.min.js — 727 KB
      • moment.min.js — 59 KB, plus moment-jdateformatparser
      • blueimp-gallery-bundle.min.js — 36 KB
      • blueimp-gallery.min.css — 8 KB, plus lightbox.css

      A 3.7 KB inline JSON template is also serialized into the HTML of every page and appended to <body>.

      Guests get all of it too, on every page.

      Analysis

      The UI extension in XWiki/Lightbox/WebHome.xml is registered on org.xwiki.platform.template.header.after with scope=wiki, and that extension point is rendered unconditionally by flamingo/global.vm. The only guard is the isLightboxEnabled configuration flag: there is no check on the action and no check on whether the page actually contains an image.

      The JSX it pulls consists of a single statement:

      require(['xwiki-lightbox'], function(lightbox) {});
      

      xwiki-lightbox then statically depends on xwiki-lightbox-description, which statically depends on moment, moment-jdateformatparser and moment-timezone — and moment-timezone resolves to the with-data build in flamingo/javascript.vm, hence the 727 KB.

      moment-timezone is used in exactly one place, updateDescriptionMetadata in lightbox.js, to format the attachment date shown in the lightbox description panel. That code only runs once a slide has actually been opened. The source already carries a comment pointing at XWIKI-19808 as the proper long-term fix for the date formatting itself.

      Suggested fix

      Two independent steps, either of which is worthwhile on its own:

      • Make xwiki-lightbox-description a lazy dependency of xwiki-lightbox (through the deferred! RequireJS plugin, or a nested require([...]) inside addSlideDescription), so the moment stack is only fetched when a slide is opened. This alone accounts for about 790 KB.
      • Do not load xwiki-lightbox at all until the page actually contains an image. initLightboxFunctionality in lightbox.js already computes the set of eligible images — it simply does not act on the set being empty.

      This is the same class of problem as XWIKI-22936.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mleduc Manuel Leduc
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: