-
Notifications
You must be signed in to change notification settings - Fork 119
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
🚀 Add minify contrib #563
base: main
Are you sure you want to change the base?
🚀 Add minify contrib #563
Conversation
@alwismt I ran all the code in the PR through GPT-4 which suggested around 4-5 fixes on each file. One thing that caught my attention is that in all the files it says the implementation is only good for small files, larger files would suffer from performance issues and suggestion using a library to do the minimization. It also mentioned how some tags/etc were not taken into account. After doing a quick search, reading on reddit found this lib that covers all the use cases: https://github.com/tdewolff/minify Would it make more sense to use that to build a middleware for fiber rather than try to implement our own minimizing logic? |
@gaby I agree that using an external library like like https://github.com/tdewolff/minify would be a more efficient solution, especially for larger files. I will integrate it into the minify middleware for fiber. Thanks for your suggestion! |
@alwismt Any progress on this? |
@alwismt Friendly ping :-) |
🚀 Add minifying HTML, CSS and JavaScript responses
Description
This PR adds a new Minify middleware for Fiber. The middleware handles minifying HTML, CSS and JavaScript responses. This is located in the
minify
directory and contains the following files:config.go
: defines the configuration options for the middleware.css_minify.go
: contains the logic for minifying CSS responses.html_minify.go
: contains the logic for minifying HTML responses.js_minify.go
: contains the logic for minifying JavaScript responses.minify.go
: contains the main middleware logic.css_minify_test.go
,html_minify_test.go
,js_minify_test.go
,minify_test.go
: contain test cases for each file and every possible test case.Related
🚀 Feature: Add minify middleware
Changes:
Added new middleware for minifying HTML, CSS and JavaScript responses.
Created a new
minify
directory in theroot
directory and added the necessary files.Added configuration options for enabling/disabling minification for HTML, CSS and JavaScript responses.
Added configuration options for excluding specific URLs and styles/scripts from minification.
Added default configuration options and a helper function for setting default values.
Added test cases for each file and possible test cases.
New feature (non-breaking change which adds functionality)
This change requires a documentation update
Usage:
Custom Config
Config
bool
yes
true
MinifyHTMLOptions
yes
MinifyHTMLOptions
bool
yes
false
MinifyCSSOptions
yes
MinifyCSSOptions
bool
yes
false
MinifyJSOptions
yes
MinifyJSOptions
Method
yes
GET
func(c *fiber.Ctx) bool
yes
nil
MinifyHTMLOptions
bool
false
bool
false
[]string
nil
MinifyCSSOptions
[]string
[]string{"*.min.css", "*.bundle.css"}
MinifyJSOptions
[]string
[]string{"*.min.js", "*.bundle.js"}