Minify and compress CSS/JS of static content folder

#!/bin/bash
cd /var/www/domain.com/web/pub/static/_cache/merged && \
find ./ -type f \
    -name "*.js" ! -name "*.min.*" ! -name "vfs_fonts*" \
    -exec echo {} \; \
    -exec uglifyjs -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/_cache/merged && \
find ./ -type f \
    -name "*.css" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec uglifycss --output {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/nl_NL && \
find ./ -type f \
    -name "*.js" ! -name "*.min.*" ! -name "vfs_fonts*" \
    -exec echo {} \; \
    -exec uglifyjs -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/nl_NL && \
find ./ -type f \
    -name "*.css" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec uglifycss --output {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/nl_NL && \
find ./ -type f \
    -name "*.html" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec htmlmin -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/nl_NL/Magento_Ui/templates && \
find ./ -type f \
    -name "*.html" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/en_US && \
find ./ -type f \
    -name "*.js" ! -name "*.min.*" ! -name "vfs_fonts*" \
    -exec echo {} \; \
    -exec uglifyjs -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/en_US && \
find ./ -type f \
    -name "*.css" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec uglifycss --output {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/en_US && \
find ./ -type f \
    -name "*.html" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec htmlmin -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;

cd /var/www/domain.com/web/pub/static/frontend/Smartwave/porto/en_US/Magento_Ui/templates && \
find ./ -type f \
    -name "*.html" ! -name "*.min.*" \
    -exec echo {} \; \
    -exec html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true -o {}.min {} \; \
    -exec rm {} \; \
    -exec mv {}.min {} \;
Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp