Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset library enhancements #174

Open
armanist opened this issue Nov 5, 2024 · 1 comment
Open

Asset library enhancements #174

armanist opened this issue Nov 5, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request new feature

Comments

@armanist
Copy link
Member

armanist commented Nov 5, 2024

No description provided.

@armanist armanist added enhancement New feature or request new feature labels Nov 5, 2024
@armanist
Copy link
Member Author

armanist commented Nov 5, 2024

Currently, assets in the application are loaded individually, resulting in multiple requests for CSS and JS files. To improve performance, we need to implement a feature that combines and minifies multiple CSS and JS assets into single files, similar to functionality provided by build tools like Gulp. This will reduce HTTP requests and optimize loading times.

The new feature should:

Combine multiple CSS files into a single minified CSS file.
Combine multiple JS files into a single minified JS file.
Dynamically generate unique filenames based on the assets’ hash to handle cache invalidation.
Implement caching to avoid regenerating files unless the assets change.
Provide an option to toggle this feature on or off for development vs. production environments.
Acceptance Criteria:

New Method in AssetManager:

Add a compileAssets(int $type): string method that:
Accepts a type parameter (CSS or JS).
Generates a hash based on the asset paths to create a unique filename.
Checks if a combined file already exists for this hash, and if so, returns its URL.
If not, concatenates and minifies the assets, saves the minified output to a file, and returns the URL.
Uses a third-party minification library (e.g., MatthiasMullie\Minify).
Update the dump Method:

Modify dump(int $type) in AssetManager to check if asset compilation is enabled.
If enabled, use compileAssets to get the URL of the combined file and output a single link/script tag.
If not, fall back to outputting individual tags for each asset.
Configuration Toggle:

Add a configuration option to enable/disable asset compilation for different environments.
Cache Invalidation:

Ensure that when assets are updated, the hash changes, generating a new filename for cache busting.
Error Handling and Logging:

Handle any errors from the minification process gracefully.
Log errors to assist with debugging if compilation fails.
Update View Helper assets():

Ensure the assets() helper function works seamlessly with the updated dump method, outputting either the combined or individual asset files as configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature
Projects
None yet
Development

No branches or pull requests

2 participants