Gzip Compression in Bottle¶

Note

For a detailed discussion, see compression

A common feature request is for Bottle to support Gzip compression, which speeds up sites by compressing static resources (like CSS and JS files) during a request.

Supporting Gzip compression is not a straightforward proposition, due to a number of corner cases that crop up frequently. A proper Gzip implementation must:

  • Compress on the fly and be fast doing so.
  • Do not compress for browsers that don’t support it.
  • Do not compress files that are compressed already (images, videos).
  • Do not compress dynamic files.
  • Support two differed compression algorithms (gzip and deflate).
  • Cache compressed files that don’t change often.
  • De-validate the cache if one of the files changed anyway.
  • Make sure the cache does not get to big.
  • Do not cache small files because a disk seek would take longer than on-the-fly compression.

Because of these requirements, it is the recommendation of the Bottle project that Gzip compression is best handled by the WSGI server Bottle runs on top of. WSGI servers such as cherrypy provide a GzipFilter middleware that can be used to accomplish this

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。