运行我的应用程序时出现Angular2 GZIP问题 [英] Angular2 GZIP issue when I run my app

查看:101
本文介绍了运行我的应用程序时出现Angular2 GZIP问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个angular2打字稿应用程序。

I have an angular2 typescript app.

我使用Firebase托管并使用cloudflare进行速度,缓存和保护。

I host with Firebase and use cloudflare for speed, caching and protection.

浏览器标题说:accept-encoding:gzip,deflate,sdch,br

The browser header says: accept-encoding:gzip, deflate, sdch, br

这会转换为app.js文件,现在缩小为1.6 mb。

This gets converted to a app.js file and is minified now to 1.6mb.

然后GZIP压缩了这个app.js文件。

I我想使用现在是GZIP压缩的app.js文件而不是原始的1.6mb app.js文件。因此,我指向index.html页面中的 app.js.gz文件,我收到一个名为的浏览器错误:

I'm wanting to use the app.js file that is now GZIP compressed rather than the original 1.6mb app.js file. Therefore, I point to the app.js.gz file in my index.html page and I get a browser error called:

app.js.gz:1 Uncaught SyntaxError:无效或意外的令牌

下面是我的app.js文件和index.html的屏幕抓取。

Below is a screen grabs of my app.js file and index.html.

如果您再提出要求,请告诉我信息或屏幕抓取。

Let me know if you request any more info or screen grabs.

似乎我需要做其他事情以使其发挥作用。
我是否需要做一些cloudflare设置才能接受.gz文件?

It seems like I need to do something else in order for it to work. Do I need to do some cloudflare settings to accept a .gz file or something?

推荐答案

那些gzips是肉对于可以使用pregzipped文件的web服务器,他们不需要为每个请求gzip或缓存它。
然后传输压缩的js,浏览器/ cloudflare处理其余的。所以你不必编辑脚本标签来使用gzip或者不要使用它。

Those gzips are meat for webservers that can use pregzipped files that they dont have to gzip it with every request or cache it. The js it then transfered compressed and the browser/cloudflare handles the rest. So you dont have to edit the script tags to use gzip or dont use it.

但是你可以简单地使用nginx并在那里启用gzip(并且不要使用.gz)对于来自cloudflare的少数请求。

But you can simply use nginx and enable gzip there (and dont use the .gz) for the few request from cloudflare.

这篇关于运行我的应用程序时出现Angular2 GZIP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆