webman 不使用nginx如何开启gzip压缩

coding
2210 1 0
1个回答

walkor
  • coding 2020-11-27

    感谢 昨天还特意去github去翻了一下 没看到麻烦了哈哈

  • fengshengchang 2022-04-20

    walkor github的方式有个bug
    1、有问题的使用方式:
    class Response extends \Webman\Http\Response
    {
    public function __construct($status = 200, array $headers = array(), $body = '')
    {
    $headers += ['Content-Encoding' => 'gzip'];
    $body = gzencode($body);
    parent::__construct($status, $headers, $body);
    }

    public function withBody($body)
    {
        $body = gzencode($body);
        return parent::withBody($body);
    }

    }

    2、具体问题点如下:
    请求/plugin/webman/push/push.js时,前端无法接收到push.js内容
    您可以试一下,不用gzip方法是没问题的
    另外,其他的js请求是正常的

  • fengshengchang 2022-04-20

    请求/plugin/webman/push/push.js时,执行了gzip的构造函数,但是没有执行withBody函数

  • walkor 2022-04-20
    return response()->file(base_path().'/vendor/webman/push/src/push.js');

    改成

    return response()->withBody(file_get_contents(base_path().'/vendor/webman/push/src/push.js'));
  • fengshengchang 2022-04-20

    请问下其他静态资源文件js和css怎么做压缩?在StaticFile中间件里面改?

年代过于久远,无法发表回答
🔝