Skip to content

Instantly share code, notes, and snippets.

@ridem
Last active October 28, 2023 12:15
Show Gist options
  • Save ridem/1dc8dd62dd81e736aade31d98b3459b0 to your computer and use it in GitHub Desktop.
Save ridem/1dc8dd62dd81e736aade31d98b3459b0 to your computer and use it in GitHub Desktop.
Download all Shopify CDN assets from a store
function fetchPageAssets(){
var downloader = $("<a id='download-file' href='' download=''></a>")
$(".ui-title-bar").append(downloader)
var assets = $("#assets-table .next-input--readonly")
assets.each(function(index, input) {
$('#download-file').attr('href', input.value);
$('#download-file')[0].click();
if (index + 1 == assets.length) {
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(25,36)
$.ajax({
url: "/admin/settings/files?direction=next&last_id="+lastItem+"&last_value="+ lastItem+"&limit=100&order=id+desc",
}).done(function(data) {
var mutationObserver = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
if (mutation.target.id && mutation.target.id == "assets-table") {
fetchPageAssets()
observer.disconnect()
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
fetchPageAssets()
function fetchPageAssets() {
var assets = $("#assets-table .next-input--readonly")
assets.each(function (index, input) {
files.push(input.value)
if (index + 1 == assets.length) {
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(25, 36)
$.ajax({
url: "/admin/settings/files?direction=next&last_id=" + lastItem + "&last_value=" + lastItem + "&limit=100&order=id+desc",
}).done(function (data) {
var mutationObserver = new MutationObserver(function (mutations, observer) {
mutations.some(function (mutation) {
if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.addedNodes[0].nextElementSibling.innerHTML.indexOf("empty") > -1
) {
downloadListFile()
observer.disconnect()
return true;
} else if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.previousSibling.className == "ui-layout ui-layout--full-width"
) {
fetchPageAssets()
observer.disconnect()
return true;
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
function downloadListFile() {
var downloader = $("<a id='download-file' href='' download='shopify-files.txt'></a>")
$(".ui-title-bar").append(downloader)
var data = 'data:application/octet-stream;base64,' + window.btoa(files.join(','));
$('#download-file').attr('href', data);
$('#download-file')[0].click();
}
var files = []
fetchPageAssets()

Instructions

  1. Go to your Shopify admin/settings/files page
  2. Open your browser Dev tools, go to the console

Then, depending on the option you choose:

Option 1 - Download all the files directly (might crash you browser)

  1. Make sure your browser is set to download files automatically and doesn't ask for the download location every time
  2. Paste the content of the console_download_files.js file, and press enter
  3. Your browser will automatically fetch each page and download every file on it. It might ask you to accept "multiple downloads" (Chrome)

Option 2 - Download a .txt file containing the list of the files to download

  1. Paste the content of the console_download_list.js file, and press enter
  2. Your browser will automatically fetch each page and download the list of all the files on the CDN. You'll then be able to use any file download manager to import the list and safely download everything.
@storefixco
Copy link

Thank you @reajkee13

@Nadeemp77
Copy link

Worked for me also...thank you for this script..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment