如果您网站的访问者使用的浏览器支持WebP格式,则CDN会为他提供图像的WebP版本(WebP版本是在网站上自动生成的) CDN端)。
为什么值得使用WebP?
使用Webp解决了Google Pagespeed Insights中的“使用现代图像格式”问题。
简而言之,在所有其他条件相同的情况下,WebP会比旧格式(png和jpeg)更好地压缩文件-这意味着它在主机上占用的空间更少,并且在浏览页面时在浏览器中加载得更快。 p>
Google积极推动WebP的实施-他们提供了以下统计信息:
如果访问者的浏览器不支持Webp,则会为访问者提供原始格式(png / jpeg)的图像,但会对其进行预压缩/优化。
如果访问者通过手机打开网站,则图像不仅会自动压缩或转换为Webp,还会自动减小宽度(以加快在移动Internet上的图像下载速度)
每次请求时,都不会即时转换,优化和压缩图像。 所有这些过程将由CDN对所请求的图像执行一次。 在后台,以免减慢向站点访问者的图像传递速度。
.htaccess 要么 php.ini..htaccessphp_value auto_prepend_file "<SITE_ROOT_DIRECTORY>/optipic-cdn-php/optipic-cdn-php/auto_prepend_file.php"
php.ini; Automatically add files before PHP document. ; http://php.net/auto-prepend-file auto_prepend_file = <SITE_ROOT_DIRECTORY>/optipic-cdn-php/optipic-cdn-php/auto_prepend_file.php
# OptiPic CDN: insert it into the Server structure
location ~* \.(png|jpg|jpeg)$ {
resolver 8.8.8.8; # Google DNS
set $cdn_host_value "cdn.optipic.io";
set $from_optipic "yes"; # to disable CDN OptiPic - set "no" value
if ($arg_no_optipic) {
set $from_optipic "no";
set $cdn_host_value $host;
}
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $cdn_host_value;
if ($from_optipic = "yes") {
rewrite ^/(.*) /site-XXXXXX/$1 break;
proxy_pass http://$cdn_host_value;
}
# get-param ?no_optipic=1 - get image from your hosting directly (without CDN OptiPic)
try_files $uri 404;
}
XXXXXX — 您的CDN OptiPic帐户中的站点IDnginx -t. nginx -s reload.htaccess 连接(Apache 代理)
#---------------------------------------
# OptiPic CDN
# Requires enabled Apache modules: `rewrite`, `proxy_module` and `proxy_http_module`
# Add new 'IfModule mod_rewrite.c' block or inject into exist one
# Get support: https://optipic.io/get-free-help/?cdn=1
<IfModule mod_rewrite.c>
RewriteEngine On
SSLProxyEngine On
RewriteCond %{QUERY_STRING} !no_optipic=
RewriteRule "^(.*)\.(jpg|jpeg|png)$" "http://cdn.optipic.io/site-XXXXXX/$1.$2" [P]
</IfModule>
#----------------------------------------
XXXXXX — 您的CDN OptiPic帐户中的站点ID.htaccess 之前,我们强烈建议您对该文件进行备份,并确保您可以通过 FTP 访问该文件。<img src="/upload/foo/bar/image.png">
<img src="//cdn.optipic.io/site-XXXXXX/upload/foo/bar/image.png">
XXXXXX — 您的CDN OptiPic帐户中的站点ID