Skip to content

Content hash for cache-busting purposes #2985

Answered by jcubic
puleddu asked this question in Q&A
Discussion options

You must be logged in to vote

I use code like this:

crc32 algorithm

// CRC32 code based on https://stackoverflow.com/a/18639999/387194
const crcTable = (() => {
    let c;
    const result = [];
    for (let n =0; n < 256; n++) {
        c = n;
        for(var k =0; k < 8; k++) {
            c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
        }
        result[n] = c;
    }
    return result;
})();

const crc32 = (str) => {
    let crc = 0 ^ (-1);

    for (let i = 0; i < str.length; i++) {
        crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
    }

    return (crc ^ (-1)) >>> 0;
};

module.exports = (str) => {
    return crc32(str).toString(36);
};

and in eleventy config

const crc32 = require(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@puleddu
Comment options

Answer selected by puleddu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants