In JavaScript possiamo impostare le immagini di sfondo usando gli attributi di dati.
La soluzione รจ la seguente:
const bgElements = document.querySelectorAll('[data-background]');
if(bgElements.length > 0) {
    bgElements.forEach(el => {
        let bgURL = el.dataset.background;
        el.style.backgroundImage = `url(${bgURL})`;
    });
}