Skip to content

Instantly share code, notes, and snippets.

@mawiseman
Last active April 1, 2022 09:31
Show Gist options
  • Save mawiseman/408c09a4d335c2ea8b3db936829bc042 to your computer and use it in GitHub Desktop.
Save mawiseman/408c09a4d335c2ea8b3db936829bc042 to your computer and use it in GitHub Desktop.
Sitecore SXA regenerate optimised files
# Run this script in Sitecore Powershell Extensions
# It will delete the minifed files from master and publish the deletions to web
# Next time the site is visited they should be re-generated (if they aren't check your settings http://bit.ly/2TfrcfC)
# TODO: When publishing, there might be a better way to target folders in the media library instead of the hardcoded list
$masterItems = Get-Item -Path master: -Query "/sitecore/media library//*[@@key='optimized-min']"
$webItems = Get-Item -Path web: -Query "/sitecore/media library//*[@@key='optimized-min']"
Write-Host "Master Items: $($masterItems.length)"
Write-Host "Web Items: $($webItems.length)"
# Set this to $true to run the actual delete and publish
if($false) {
Write-Host ""
Write-Host "Deleting optimized-min files"
$masterItems | Remove-Item
Write-Host ""
Write-Host "Publishing deleted items"
Publish-Item -Path "master:\media library\Base Themes" -Recurse -Language "en" -Target web
Publish-Item -Path "master:\media library\Extension Themes" -Recurse -Language "en" -Target web
Publish-Item -Path "master:\media library\Themes" -Recurse -Language "en" -Target web
Publish-Item -Path "master:\media library\Feature" -Recurse -Language "en" -Target web
Write-Host ""
Write-Host "Master Items: $($masterItems.length)"
Write-Host "Web Items: $($webItems.length)"
}
else {
Write-Host "Nothing done"
}
Write-Host "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment