twopluszero / next-images

Import images in Next.js (supports jpg, jpeg, svg, png and gif images)
MIT License
948 stars 67 forks source link

RFC: uglify option #47

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hello thank you for your maintaining.

I wanna reduce filename in production.

So how about add uglifyFileName option?

If you allow, I wanna send a PR using this library.

arefaslani commented 4 years ago

Hey @TroyTae! Thanks for reporting this, but to be honest I didn't get what you mean by uglifying filename and BTW we're using hashes in filenames to deprecate caches on new builds. The other thing is that we want it to be super small and minimal. Please don't hesitate to reopen this issue if you think we definitely need this.

ghost commented 4 years ago

@arefaslani Hello, thank you for reply. I didn't write issue in detail. Sorry 😅 As you know, next-images uses [name-hash] pattern. But I think generated file name is too long. So I made uglify-set, this module can reduce file name length:

poster1c7f86a319052c3df3795d6a637d0dd.png -> A.png

If we provide this option, people can reduce bundle size in production :)

ghost commented 4 years ago

@arefaslani Hmmm apart from the above comment, it seems this repo is configured that author cannot reopen issue

arefaslani commented 4 years ago

Sorry that was something I wasn't aware of that.

The problem with uglifying names to be like A.png is that the chance that you be able to expire previous caches will reduce dramatically. The reason we're using hashes in filenames is that if you change the image in your app, then it'll change the hash and the browser understands to replace the new image with the old one. Else it'll still use the cached image.

ghost commented 4 years ago

@arefaslani Isn't it nextjs control the caching of static files? The files of public directory maintain same name. But if I change file, it reflects well.

arefaslani commented 4 years ago

The browser caches files based on the names and it's a good practice to generate filenames that reduce the chance of mistakes like this. Rails for example does the same thing for asset names.

ghost commented 4 years ago

@arefaslani Ah I see, I think it'll be fine because Etag is changed automatically. Anyway I understand what you mean. Thank you for explaining 👍