Skip to content

Instantly share code, notes, and snippets.

@erikhansen
Last active May 20, 2024 03:21
Show Gist options
  • Select an option

  • Save erikhansen/c1b88dce68c8cd76b042c1e1b82b0703 to your computer and use it in GitHub Desktop.

Select an option

Save erikhansen/c1b88dce68c8cd76b042c1e1b82b0703 to your computer and use it in GitHub Desktop.
Load all urls from a sitemap.xml file
#!/bin/bash
# This script crawls all urls in a /sitemap.xml file and loads them, effectively priming the cache
# Usage: ./warm_cache.sh www.example.com
time wget --quiet https://$1/sitemap.xml --output-document - | \
egrep -o "https?://[^<]+" | \
grep $1 | \
grep -v "jpg" | \
xargs -i -d '\n' curl --output /dev/null --silent --write-out '%{http_code} %{time_total}ms %{url_effective} \n' {}
@erikhansen

erikhansen commented Mar 1, 2019 •

Copy link
Copy Markdown
Author

While caching shouldn't solely be relied upon for site performance, there are certain instances where priming the cache is useful. In my case, a client regularly imports products with hundreds of images each (for 360° views) and when the PDP is loaded for the first time, it takes 1-2 minutes for Magento to generate the product images. In my case, the php bin/magento catalog:images:resize command does not generate the images necessary since the 360° images are powered by a third-party extension and don't tie into that command.

Example output of this script:

200 0.263ms https://example.com/example-url-1.html
200 0.263ms https://example.com/example-url-2.html
200 113.260ms https://example.com/example-url-3.html
400 0.257ms https://example.com/example-url-broken-url.html

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