通過在Get請求的Header中添加Accept-Encoding: gzip,OSS可對HTML、JavaScript、XML、JSON等常見網頁靜態檔案進行gzip壓縮,協助節省頻寬並提高傳輸效率。
前提條件
檔案大於或者等於1 KB。
Content-Type必須為以下之一:
text/cache-manifest、text/xml、text/css、text/html、text/plain、application/javascript、application/x-javascript、application/rss+xml、application/json、text/json。
注意事項
啟用gzip壓縮且壓縮生效後,GetObject、HeadObject等介面回應標頭將增加Content-Encoding: gzip,不再返回ETag、Content-Length和Accept-Ranges欄位資訊。
API樣本
請求樣本
GET /example.txt HTTP/1.1 Host: examplebucket.oss-cn-hangzhou.aliyuncs.com Accept: */* Accept-Encoding: gzip返回樣本
HTTP/1.1 200 OK Server: AliyunOSS Date: Tue, 19 Nov 2024 08:38:22 GMT Content-Type: text/plain Connection: keep-alive Vary: Accept-Encoding x-oss-request-id: ********** Last-Modified: Tue, 19 Nov 2024 06:04:02 GMT x-oss-object-type: Normal x-oss-hash-crc64ecma: ******************** x-oss-storage-class: Standard x-oss-version-id: *************************************** x-oss-ec: ************ Content-Disposition: attachment x-oss-force-download: true Content-MD5: ****************** x-oss-server-time: 35 Content-Encoding: gzip