metalmatze / laravel-html-cachebusting

Extends laravel's HtmlBuilder with styleBust() & scriptBust() which insert the file's md5 to the url.
MIT License
16 stars 1 forks source link

Performance of MD5 and file IO ? #1

Open ejunker opened 10 years ago

ejunker commented 10 years ago

Thank you for this library, it looks like it will be very useful.

I know MD5 is a fairly fast hash algorithm but are there any concerns about performance because each web request is going to do file IO to check if the file exists and then MD5 the file?

Using Laravel's Cache would allow you to cache the MD5 hash and then later requests could just get the hash from the cache. If you did a new deployment you would have to clear the cache since files may have changed.

Another idea I had was to have a config file that has a hash/version number to use for all files. There could be an artisan command that you would run after deployment to update the hash/version number in the config file. You could probably just randomly generate a hash and not have to worry about hash collisions/duplication.

metalmatze commented 10 years ago

I tested the IO for some css files and it took about 2ms, that's why I had no doubt to hashing it on each request.

If we would use caching I'd probably go with laravel's build-in caching. Maybe we could set the cache time to 1min. Since it is really fast to cache it would be no problem to cache every minute. But if you had multiple request each minute they would be cached.

What do you think?