Search code examples
imageurluriprotocolsurl-scheme

What is the image:// prefix?


Quote from the Luckysheet source code:

image://css/loading.gif

Is this an image protocol? I've never seen this prefix before, could anyone explain what it is?


Solution

  • No, it's just a prefix used later to differentiate between two types of values:

    const luckysheetloadingImage = function (config) {
        if(typeof config.image==="function"){
            return config.image()
        }
        const regE = new RegExp("^(image|path)://");
        const regResult = regE.exec(config.image);
        let imageHtml = '';
        if (regResult !== null) {
            const prefix = regResult[0];
            const type = regResult[1];
            const imageStr = regResult.input.substring(prefix.length);
            switch (type) {
                case "image":
                    imageHtml = `<div class="image-type" style="background-image: url(${imageStr});"></div>`;
                    break;
    

    I would probably have used two different attributes instead of encoding information in the string.