The performance-tool.py script is designed to analyze and improve the performance of custom themes in web projects. It performs various checks to identify potential issues in theme files, such as missing attributes, non-optimized images, and inline styles/scripts.
The tool performs the following checks:
- Libraries.yml (Async/Defer): Ensures JavaScript files in
libraries.ymlhaveasyncordeferattributes. - Non-Optimized Images (CSS & Twig): Detects non-WebP image formats in CSS and Twig files.
- Inline CSS/JS in Twig: Flags excessive inline
<style>and<script>tags in Twig templates. - Missing Alt Attributes: Identifies
<img>tags in Twig files that are missingaltattributes for accessibility. - Large Images in CSS/Twig: Checks for images larger than 500 KB in CSS and Twig files.
- Missing Async/Defer in
<script>: Ensures inline<script>tags in Twig files haveasyncordeferattributes.
- Python 3.x
- Dependencies listed in
requirements.txt:PyYAML
This repository includes GitHub workflows to automate testing and validation:
- Test Performance Tool Action: This workflow, defined in
.github/workflows/test.yml, allows you to manually trigger a test of the performance tool using theworkflow_dispatchevent. It runs the tool against the specified theme directory (./themes/custom/custom-themeby default) to ensure it functions as expected.
- Clone the repository:
git clone https://github.com/rahulsavaria/Performance-tool.git cd Performance-tool
- Run the script with the following command:
python3 performance-tool.py <path-to-theme-directory>
- Replace
<path-to-theme-directory>with the path to the theme folder you want to analyze. - Review the output for identified issues and recommendations.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-name
- Commit your changes and push the branch:
git commit -am "Add new feature" git push origin feature-name - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.