未设置Content-Type导致js和css文件失效


最近用nginx部署一个前端应用后出现了很诡异的问题,构建后html访问正常,请求的css和js也都正常返回,但是js并没有执行且页面没有任何样式。

html

network响应如下

file

最开始认为是package.json的问题,但是加入homepage属性后问题依然没有解决,多次搜索后确定因没有设置Content-Type导致浏览器无法识别js和css文件

ngxin安装后自带一个mime文件,该文件默认在/etc/nginx下,引入后基本可以解决这类问题

/etc/nginx

修改nginx.conf如下(引入mime文件)

conf

最后看一下response header是否已经有了Content-Type

js header

css header

越诡异的问题越简单


Author: Maple
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Maple !
  TOC