[HTML5]配置Ngnix服务器支持manifest
HTML5有一个相当诱人的特性,就是 Application Cache,即离线存储。
可以在没有网络的情况下,不会给用户一个“网络不可用”这种很不友好的用户提示。当然,更主要的是,我们希望可以在没有网络的状态下,依然带给用户较高的用户体验。
使用离线存储,除了需要在html tag标签增加<manifest>,列出需要缓存的清单,还必须在服务器端进行相应的配置。
由于开发中使用Ngnix服务器,这里我以Ngnix服务器配置为例。说明如果进行服务器的配置,支持HTML5 Application Cache特性。
1. 找到Ngnix服务器配置文件mime.types
- root@mdev usr # cd /etc/httpd/
- root@mdev httpd # ll
- total 28K
- 8.0K drwxr-xr-x 2 root root 4.0K Apr 10 2010 conf
- 8.0K drwxr-xr-x 2 root root 4.0K Apr 10 2010 conf.d
- 4.0K lrwxrwxrwx 1 root root 19 Apr 10 2010 logs -> ../../var/log/httpd
- 4.0K lrwxrwxrwx 1 root root 29 Apr 10 2010 modules -> ../../usr/lib64/httpd/modules
- 4.0K lrwxrwxrwx 1 root root 13 Apr 10 2010 run -> ../../var/run
- root@mdev httpd # cd conf
- root@mdev conf # ll
- total 60K
- 40K -rw-r--r-- 1 root root 33K Sep 4 2009 httpd.conf
- 20K -rw-r--r-- 1 root root 13K Sep 4 2009 magic
- root@mdev conf # cd ..
- root@mdev httpd # cd conf.d/
- root@mdev conf.d # ll
- total 24K
- 8.0K -rw-r--r-- 1 root root 566 Sep 4 2009 proxy_ajp.conf
- 8.0K -rw-r--r-- 1 root root 392 Sep 4 2009 README
- 8.0K -rw-r--r-- 1 root root 299 Sep 4 2009 welcome.conf
- root@mdev conf.d # cd /usr/local/nginx/conf/
2. 编辑mime.types
- root@mdev conf # vi mime.types
3. 添加manifest文件映射
- types {
- text/html html htm shtml;
- text/css css;
- text/xml xml rss;
- image/gif gif;
- image/jpeg jpeg jpg;
- application/x-javascript js;
- application/atom+xml atom;
- text/mathml mml;
- text/plain txt;
- text/vnd.sun.j2me.app-descriptor jad;
- text/vnd.wap.wml wml;
- text/x-component htc;
- image/png png;
- image/tiff tif tiff;
- image/vnd.wap.wbmp wbmp;
- image/x-icon ico;
- image/x-jng jng;
- image/x-ms-bmp bmp;
- image/svg+xml svg;
- application/java-archive jar war ear;
- application/mac-binhex40 hqx;
- application/msword doc;
- application/pdf pdf;
- application/postscript ps eps ai;
- application/rtf rtf;
- application/vnd.ms-excel xls;
- application/vnd.ms-powerpoint ppt;
- application/vnd.wap.wmlc wmlc;
- application/vnd.wap.xhtml+xml xhtml;
- application/x-cocoa cco;
- application/x-java-archive-diff jardiff;
- application/x-java-jnlp-file jnlp;
- application/x-makeself run;
- application/x-perl pl pm;
- application/x-pilot prc pdb;
- application/x-rar-compressed rar;
- application/x-RedHat-package-manager rpm;
- application/x-sea sea;
- application/x-shockwave-flash swf;
- application/x-stuffit sit;
- application/x-tcl tcl tk;
- application/x-x509-ca-cert der pem crt;
- application/x-xpinstall xpi;
- application/zip zip;
- application/octet-stream bin exe dll;
- application/octet-stream deb;
- application/octet-stream dmg;
- application/octet-stream eot;
- application/octet-stream iso img;
- application/octet-stream msi msp msm;
- audio/midi mid midi kar;
- audio/mpeg mp3;
- audio/x-realaudio ra;
- video/3gpp 3gpp 3gp;
- video/mpeg mpeg mpg;
- video/quicktime mov;
- video/x-flv flv;
- video/x-mng mng;
- video/x-ms-asf asx asf;
- video/x-ms-wmv wmv;
- video/x-msvideo avi;
- application/x-nokia-widget wgz;
- text/cache-manifest mf manifest
- }
如果有过IIS配置经验的,这里的mime.types 和IIS的文件名映射原理是一样的,即对于文件后缀名是mf 或者 manifest 采用 text/cache-manifest 方式解析。
4. 重启 Ngnix 服务器:
- root@mdev conf # /etc/init.d/httpd restart
- Stop nginx ...
- Starting nginx ...
通过chrom 访问站点,即可看到离线缓存后的效果:
相关推荐
wusiye 2020-10-23
表格的现在还是较为常用的一种标签,但不是用来布局,常见处理、显示表格式数据。在HTML网页中,要想创建表格,就需要使用表格相关的标签。<table> <tr> <td>单元格内的文字</td> ...
gufudhn 2020-08-09
nercon 2020-08-01
swiftwwj 2020-07-21
nercon 2020-07-16
饮马天涯 2020-07-05
Lophole 2020-06-28
gufudhn 2020-06-12
csstpeixun 2020-06-11
huzijia 2020-06-09
WebVincent 2020-06-06
行吟阁 2020-05-30
qsdnet我想学编程 2020-05-26
gufudhn 2020-05-25
qsdnet我想学编程 2020-05-19
suixinsuoyu 2020-05-15
HSdiana 2020-05-15
PioneerFan 2020-05-15