简体   繁体   English

.NET Core 2 / Angular 5图像压缩

[英].NET Core 2/Angular 5 Image Compression

This is a very simple question. 这是一个非常简单的问题。 I have a simple website with a few jpeg images. 我有一个带有几个jpeg图像的简单网站。 I've been reading about the power of enabling g-zip on the server, and intend to do that to reduce file sizes across js/html/css files. 我一直在阅读有关在服务器上启用g-zip的功能,并打算这样做以减少js / html / css文件中的文件大小。 However, I'm not entirely sure how to reduce the size of images sent over the wire. 但是,我不太确定如何减小通过网络发送的图像的大小。 Should images be compressed manually before being loaded onto the server, or is there some compression tool that compresses images on the server when they are requested? 是否应在将图像加载到服务器之前对其进行手动压缩,或者在请求时是否有某种压缩工具在服务器上压缩图像? I imagine some combination of both would be ideal, but I can't seem to find a best practice for this. 我想将两者结合起来比较理想,但是我似乎找不到最佳实践。 Thank you for your time! 感谢您的时间!

Images should be ideally served as they are, they usually are and should be stored already compressed. 理想情况下应按原样提供图像,通常是并且应该将其压缩存储。 There are various tools that help you compress images. 有多种工具可以帮助您压缩图像。 You can do so manually with online tools such as TinyPNG . 您可以使用TinyPNG等在线工具手动进行操作

Or you can integrate image optimization into your workflow, with gulpfile and package gulp-imagemin . 或者,您可以使用gulpfile和gulp-imagemin软件包将图像优化集成到您的工作流程中。

There are certainly ways to do that automatically on the server as well. 当然,也有一些方法可以在服务器上自动执行此操作。 One such example is Google PageSpeed Module, but it's only available when using Nginx/Apache as reverse proxy. 其中一个示例是Google PageSpeed模块,但仅在使用Nginx / Apache作为反向代理时才可用。 PageSpeed Image Filter Documentation PageSpeed图像过滤器文档

大多数图像(我认为BMP和SVG除外)都是二进制文件,并且已经被压缩(与javascript,html,css文件不同),因此除非您想降低其质量(例如, JPEG-有损压缩),对于每个请求,您可能都不应该这样做。

If you use a mac, I recommend using ImageOptim . 如果您使用的是Mac,建议您使用ImageOptim It will hide all the details of which software to use for which image format. 它将隐藏用于哪种图像格式的哪个软件的所有详细信息。

Even better if you use Github, try Shrink.sh . 如果使用Github更好,请尝试Shrink.sh It will create automatically detect images in your project and submit pull request with optimized version of them. 它将在您的项目中自动创建检测图像并提交优化版本的拉取请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM