简体   繁体   English

压缩网站上的html,css和js文件

[英]Compression of html, css and js files on a website

I am really sorry for the title of the question. 我真的很抱歉这个问题的标题。 I had no idea what proper title shall I give to this question. 我不知道该问题我应该给什么头衔。

The question is referring to this link: 问题是指向此链接:

http://iarouse.com/admin-transform-alt/dist-v1.2.1/index.html#/pages/signin http://iarouse.com/admin-transform-alt/dist-v1.2.1/index.html#/pages/signin

This is priview of a template. 这是模板的主视图。 When I open dev tool in Chrome and check the network I/O, on the size column there it shows me different file size and content size. 当我在Chrome中打开开发工具并检查网络I / O时,在“大小”列上会显示不同的文件大小和内容大小。 for example ui.js is about 200kb of size but it has 800kb of content. 例如ui.js的大小约为200kb,但内容为800kb。

How could that be? 怎么可能 What kind of compression is it? 这是什么压缩方式?

Also when I downloaded this template and ran on my local, it showed the same file size as well as the content size. 同样,当我下载此模板并在本地运行时,它显示相同的文件大小以及内容大小。 :( How can I get this type of thing in my website. The template is pretty and needs a lot of time to load. An kind of leads or info would be of great help. :(我怎么能在我的网站上得到这种东西。模板很漂亮,需要很多时间来加载。一种潜在客户或信息会很有帮助。

The size is smaller than the content because of compression, probably gzip. 由于压缩,大小可能比内容小,可能是gzip。 Gzip is regularly used with http to make text resources faster to load. Gzip通常与http一起使用,以使文本资源的加载速度更快。 Most web servers support gzip compression. 大多数Web服务器都支持gzip压缩。 Look at the documentation for your web server to find out how to turn it on. 查看您的Web服务器的文档,以了解如何打开它。

Okay found it! 好吧找到了!

This is a gzip compression of HTML, CSS and JS files which typically saves around fifty to seventy percent of the file size. 这是HTML,CSS和JS文件的gzip压缩,通常可以节省大约50%至70%的文件大小。

Source: http://www.feedthebot.com/pagespeed/enable-compression.html 来源: http//www.feedthebot.com/pagespeed/enable-compression.html

Now since mine is running on a NodeJs server which is using Express, I enabled this by adding the following line to app.js file. 现在,由于我的服务器正在使用Express的NodeJs服务器上运行,因此我通过在app.js文件中添加以下行来启用此功能。

app.use(express.compress());

Refer: Node.js: Gzip compression? 请参阅: Node.js:Gzip压缩?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM