https://github.com/xp-forge/web-compression
Web compression
https://github.com/xp-forge/web-compression
Last synced: 11 months ago
JSON representation
Web compression
- Host: GitHub
- URL: https://github.com/xp-forge/web-compression
- Owner: xp-forge
- Created: 2024-05-30T15:51:55.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-30T15:53:40.000Z (about 2 years ago)
- Last Synced: 2025-05-15T10:08:53.255Z (about 1 year ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
Web compression
===============
[](https://github.com/xp-forge/web-compression/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-forge/web-compression)
[HTTP compression](https://developer.mozilla.org/en-US/docs/Web/HTTP/Compression) for the XP Framework, implemented as filter.
Example
-------
The following shows how to enable on-the-fly compression for HTTP responses. Depending on the *Accept-Encoding* header the client sends, the server-supported compression algorithms and the length of the content, the response is compressed, saving bandwidth.
```php
use web\{Application, Filters};
use web\filters\CompressResponses;
class Service extends Application {
public function routes() {
return new Filters([new CompressResponses()], function($req, $res) {
$content= /* ... */;
$res->answer(200);
$res->send($content, 'text/html; charset=utf-8');
});
}
}
```