Giter Site home page Giter Site logo

mediawiki-lazyload's Introduction

MediaWiki Lazyload Extension

An extension to delay loading of images on MediaWiki pages.

Requirements

Lazyload extension requires MediaWiki 1.25 or higher.

Installation

To install the extension, place the entire Lazyload directory within your MediaWiki extensions directory, then add the following line to your LocalSettings.php file:

wfLoadExtension( 'Lazyload' );

If you are using the APNG extension on your wiki, please upgrade it to 0.2.0 or higher.

Configuration

Lazyload extension supports dynamically replace image hosts or disable HiDPI support for certain cases in JavaScript. This is particularly useful when your wiki wants to use multiple CDNs for various conditions.

mw.config.set('Lazyload.imageHost', YOUR_IMAGE_HOST);
mw.config.set('Lazyload.disableHidpi', true);

A use case in 52Poké Wiki is setting the image host to CDN only for non-logged in users, and another CDN domain backed by malasada for browsers supporting WebP to minimize traffic cost.

(function() {
    if (mw.config.get('wgUserName')) {
        return;
    }
    mw.config.set('Lazyload.imageHost', '//s0.52poke.wiki');
    mw.config.set('Lazyload.disableHidpi', true);

    function testWebP(callback) {
        var webP = new Image();
        webP.onload = webP.onerror = function () {
            callback(webP.height === 2);
        };
        webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    }

    testWebP(function (supported) {
        if (supported) {
            mw.config.set('Lazyload.imageHost', '//s1.52poke.wiki');
        }
    });
})();

License

MIT

mediawiki-lazyload's People

Contributors

alistair3149 avatar ikasty avatar mudkipme avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.