WO2016146009A1 - Html page compression method and device - Google Patents

Html page compression method and device Download PDF

Info

Publication number
WO2016146009A1
WO2016146009A1 PCT/CN2016/075942 CN2016075942W WO2016146009A1 WO 2016146009 A1 WO2016146009 A1 WO 2016146009A1 CN 2016075942 W CN2016075942 W CN 2016075942W WO 2016146009 A1 WO2016146009 A1 WO 2016146009A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
compression
html page
segment
compressed
Prior art date
Application number
PCT/CN2016/075942
Other languages
French (fr)
Chinese (zh)
Inventor
张荣华
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2016146009A1 publication Critical patent/WO2016146009A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present invention relates to the field of the Internet, and in particular, to a Html page compression method and apparatus.
  • the current Html page compression process is: receiving a browser request, the server returns the Html page corresponding to the request, and dot the Html page, and performs page compression after the dot. Therefore, the current Html page compression, in any request, you need to compress the data of the entire page, resulting in greater server pressure.
  • an embodiment of the present invention provides a Html page compression method, the method comprising:
  • Html page compression data which specifically includes:
  • the static data compressed segment and the dynamic data compressed segment are encapsulated by a compressed header information and a compressed tail information.
  • the method before acquiring the static data compression segment and compressing the dynamic data, the method includes:
  • the static data is compressed into a static data compression segment and cached.
  • the static data is compressed into a static data compression segment and cached, and specifically includes:
  • the static data is compressed in a compression request to generate at least one static data compression segment, and the at least one static data compression segment is stored.
  • the static data or the dynamic data is the header data or the middle data of the Html page.
  • the z_sync_flush function is called to perform compression.
  • invoking the z_full_flush function to compress the central data of the Html page includes:
  • the compression header information formed on the empty string is deleted.
  • each static data compression segment includes dictionary data to be decompressible separately.
  • the merging into the Html page compression data according to the original order of the Html page specifically includes:
  • the static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of a character string.
  • the method further includes:
  • an embodiment of the present invention provides an Html page compression apparatus, the apparatus comprising:
  • the calling module is configured to obtain a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request;
  • a compression module configured to compress dynamic data corresponding to the Html page into a dynamic data compression segment
  • a processing module configured to merge the static data compression segment and the dynamic data compression segment into Html page compression data, and send the Html page compression data to a browser.
  • the processing module is configured to:
  • the static data compression segment and the dynamic data segment are merged into Html page compressed data according to the original order of the Html page.
  • the static data compressed segment and the dynamic data compressed segment are encapsulated by a compressed header information and a compressed tail information.
  • the compression module is configured to compress the static data in a compression request to generate at least one static data compression segment
  • the device further includes a storage module, the storage module Used for:
  • the compressed file will contain a compressed header information formed on the empty string. And further deleting the compression header information formed on the empty string to facilitate the subsequent "merging of data compression segments", which will be explained in detail below.
  • the static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of the string.
  • the static content on the Html page has been pre-compressed and cached, it avoids a large amount of repeated compression every time the request server is required, which greatly reduces the computing pressure of the server.
  • the dynamic data here is dot data.
  • the compression module 20 is configured to:
  • each compressed package will carry the full DEFLATE header and trailer information. For some browsers, these multiple complete archives are not recognized. So in the java environment, a java implementation version of zlib is introduced: jzlib, jzlib supports the flush_mode (jzlib) in compression, so in this embodiment, the z_full_flush function and the z_sync_flush function are respectively called to compress the above-mentioned partial data to obtain Static data compression segment and dynamic data compression segment.
  • the Html page compression method and apparatus of the present invention can pre-compress and cache the static content on the Html page, and when receiving the browser request, can only compress the dynamic data in the Html page, and Static content is returned after merging. In this way, it avoids a lot of compression every time the request server needs, which greatly reduces the computing pressure of the server.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

An Html page compression method and device. The method comprises: acquiring a static data compressed section of a corresponding Html page in a cache according to an http header in a browser request, and compressing dynamic data corresponding to the Html page into a dynamic data compressed section; and merging the static data compressed section and the dynamic data compressed section into Html page compressed data, and sending the Html page compressed data to a browser. The static content on an Html page can be pre-compressed and cached, and when a browser request is received, it is possible that only dynamic data in the Html page is compressed and merged with the static content and then returned. Therefore, conducting a large amount of compression when requesting a server each time is avoided, thereby greatly reducing the calculation pressure of the server.

Description

Html页面压缩方法及装置Html page compression method and device
本申请要求2015年03月17日递交的申请号为201510115508.0、发明名称为“Html页面压缩方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims the priority of the Chinese Patent Application No. 201510115508.0, the entire disclosure of which is hereby incorporated by reference.
技术领域Technical field
本发明涉及互联网领域,尤其是涉及一种Html页面压缩方法及装置。The present invention relates to the field of the Internet, and in particular, to a Html page compression method and apparatus.
背景技术Background technique
目前的Html页面压缩的过程是:接收到浏览器的请求,服务器返回与该请求相应的Html页面,并对该Html页面打点,并在打点之后进行页面压缩。所以目前的Html页面压缩,在任何一次请求时,都需要对整个页面的数据进行压缩,导致服务器压力较大。The current Html page compression process is: receiving a browser request, the server returns the Html page corresponding to the request, and dot the Html page, and performs page compression after the dot. Therefore, the current Html page compression, in any request, you need to compress the data of the entire page, resulting in greater server pressure.
发明内容Summary of the invention
本发明的目的在于提供一种Html页面压缩方法及装置。It is an object of the present invention to provide a Html page compression method and apparatus.
为实现上述发明目的之一,本发明一实施方式提供了一种Html页面压缩方法,所述方法包括:To achieve one of the above objects, an embodiment of the present invention provides a Html page compression method, the method comprising:
根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段,以及将与所述Html页面对应的动态数据压缩为动态数据压缩段;Obtaining a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request, and compressing the dynamic data corresponding to the Html page into a dynamic data compression segment;
将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。Combining the static data compression segment and the dynamic data compression segment into Html page compression data, and transmitting the Html page compression data to a browser.
作为本发明一实施方式的进一步改进,将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,具体包括:As a further improvement of an embodiment of the present invention, the static data compression segment and the dynamic data compression segment are combined into Html page compression data, which specifically includes:
将所述静态数据压缩段与所述动态数据压缩段按照所述Html页面的原始顺序合并为Html页面压缩数据。And compressing the static data compression segment and the dynamic data compression segment into Html page compression data according to an original sequence of the Html page.
作为本发明一实施方式的进一步改进,所述Html页面压缩数据中,通过一个压缩头信息和一个压缩尾信息将所述静态数据压缩段和所述动态数据压缩段封装。As a further improvement of an embodiment of the present invention, in the Html page compressed data, the static data compressed segment and the dynamic data compressed segment are encapsulated by a compressed header information and a compressed tail information.
作为本发明一实施方式的进一步改进,在获取静态数据压缩段及压缩动态数据前,所述方法包括:As a further improvement of an embodiment of the present invention, before acquiring the static data compression segment and compressing the dynamic data, the method includes:
接收浏览器请求;Receiving a browser request;
根据所述浏览器请求中的http header生成对应的Html页面;Generating a corresponding Html page according to the http header in the browser request;
将所述Html页面的静态数据和动态数据剥离; Stripping static data and dynamic data of the Html page;
将所述静态数据压缩为静态数据压缩段并缓存。The static data is compressed into a static data compression segment and cached.
作为本发明一实施方式的进一步改进,将所述静态数据压缩为静态数据压缩段并缓存,具体包括:As a further improvement of an embodiment of the present invention, the static data is compressed into a static data compression segment and cached, and specifically includes:
将所述静态数据在一次压缩请求中完成压缩,以生成至少一个静态数据压缩段,并存储所述至少一个静态数据压缩段。The static data is compressed in a compression request to generate at least one static data compression segment, and the at least one static data compression segment is stored.
作为本发明一实施方式的进一步改进,所述方法在对静态数据压缩及对动态数据压缩时具体包括:As a further improvement of an embodiment of the present invention, the method specifically includes: when compressing static data and compressing dynamic data:
若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
作为本发明一实施方式的进一步改进,调用z_full_flush函数对Html页面的中部数据进行压缩具体包括:As a further improvement of an embodiment of the present invention, invoking the z_full_flush function to compress the central data of the Html page includes:
在Html页面中部数据的字符串头部加入空字符串后进行压缩;Compressing after adding an empty string to the string header of the data in the middle of the Html page;
将在所述空字符串上形成的压缩头信息删除。The compression header information formed on the empty string is deleted.
作为本发明一实施方式的进一步改进,每个静态数据压缩段均包括字典数据,以可单独进行解压缩。As a further improvement of an embodiment of the present invention, each static data compression segment includes dictionary data to be decompressible separately.
作为本发明一实施方式的进一步改进,按照所述Html页面的原始顺序合并为Html页面压缩数据具体包括:As a further improvement of an embodiment of the present invention, the merging into the Html page compression data according to the original order of the Html page specifically includes:
将所述静态数据压缩段和所述动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。The static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of a character string.
作为本发明一实施方式的进一步改进,所述方法还包括:As a further improvement of an embodiment of the present invention, the method further includes:
配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式。Configure the Http response header to inform the browser of the compression format of the Html page compressed data it receives.
为实现上述发明目的之一,本发明一实施方式提供了一种Html页面压缩装置,所述装置包括:To achieve one of the above objects, an embodiment of the present invention provides an Html page compression apparatus, the apparatus comprising:
调取模块,用于根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段;The calling module is configured to obtain a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request;
压缩模块,用于将与所述Html页面对应的动态数据压缩为动态数据压缩段;a compression module, configured to compress dynamic data corresponding to the Html page into a dynamic data compression segment;
处理模块,用于将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。 And a processing module, configured to merge the static data compression segment and the dynamic data compression segment into Html page compression data, and send the Html page compression data to a browser.
作为本发明一实施方式的进一步改进,所述处理模块用于:As a further improvement of an embodiment of the present invention, the processing module is configured to:
将所述静态数据压缩段与所述动态数据段按照所述Html页面的原始顺序合并为Html页面压缩数据。The static data compression segment and the dynamic data segment are merged into Html page compressed data according to the original order of the Html page.
作为本发明一实施方式的进一步改进,所述Html页面压缩数据中,通过一个压缩头信息和一个压缩尾信息将所述静态数据压缩段和所述动态数据压缩段封装。As a further improvement of an embodiment of the present invention, in the Html page compressed data, the static data compressed segment and the dynamic data compressed segment are encapsulated by a compressed header information and a compressed tail information.
作为本发明一实施方式的进一步改进,所述处理模块还用于:As a further improvement of an embodiment of the present invention, the processing module is further configured to:
接收浏览器请求;Receiving a browser request;
根据所述浏览器请求中的http header生成对应的Html页面;Generating a corresponding Html page according to the http header in the browser request;
将所述Html页面的静态数据和动态数据剥离;所述压缩模块还用于:Separating static data and dynamic data of the Html page; the compression module is further configured to:
将所述静态数据压缩为静态数据压缩段并缓存。The static data is compressed into a static data compression segment and cached.
作为本发明一实施方式的进一步改进,所述压缩模块用于将所述静态数据在一次压缩请求中完成压缩,以生成至少一个静态数据压缩段,所述装置还包括存储模块,所述存储模块用于:As a further improvement of an embodiment of the present invention, the compression module is configured to compress the static data in a compression request to generate at least one static data compression segment, and the device further includes a storage module, the storage module Used for:
存储所述至少一个静态数据压缩段。Storing the at least one static data compression segment.
作为本发明一实施方式的进一步改进,所述压缩模块用于:As a further improvement of an embodiment of the present invention, the compression module is used to:
若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
作为本发明一实施方式的进一步改进,所述处理模块用于:As a further improvement of an embodiment of the present invention, the processing module is configured to:
在Html页面中部数据的字符串头部加入空字符串后供所述压缩模块进行压缩;Adding an empty string to the string header of the data in the middle of the Html page for compression by the compression module;
将在所述空字符串上形成的压缩头信息删除。The compression header information formed on the empty string is deleted.
作为本发明一实施方式的进一步改进,每个静态数据压缩段均包括字典数据,以可单独进行解压缩。As a further improvement of an embodiment of the present invention, each static data compression segment includes dictionary data to be decompressible separately.
作为本发明一实施方式的进一步改进,所述处理模块用于:As a further improvement of an embodiment of the present invention, the processing module is configured to:
将所述静态数据压缩段和所述动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。The static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of a character string.
作为本发明一实施方式的进一步改进,所述装置还包括配置模块,用于:As a further improvement of an embodiment of the present invention, the device further includes a configuration module, configured to:
配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式。Configure the Http response header to inform the browser of the compression format of the Html page compressed data it receives.
相对于现有技术,本发明的技术效果在于:本发明的Html页面压缩方法及装置可以 将Html页面上的静态内容预先压缩,并缓存,当接收到浏览器请求时,可只将Html页面中的动态数据的压缩,并与静态内容合并后返回,如此,避免了每次请求服务器都需要进行大量的压缩,大大降低了服务器的计算压力。Compared with the prior art, the technical effect of the present invention is that the Html page compression method and device of the present invention can be The static content on the Html page is pre-compressed and cached. When receiving the browser request, only the dynamic data in the Html page can be compressed and merged with the static content, so that each request is avoided. A lot of compression is needed, which greatly reduces the computing pressure on the server.
附图说明DRAWINGS
图1是本发明一实施方式中Html页面压缩方法的流程图;1 is a flowchart of a Html page compression method according to an embodiment of the present invention;
图2是本发明一实施方式中服务器接收浏览器请求后,对该请求进行反馈的完整工作流程图;2 is a complete working flow chart of feedback of a request by a server after receiving a browser request according to an embodiment of the present invention;
图3是本发明一实施方式中Html页面压缩方法的示意图;3 is a schematic diagram of a Html page compression method according to an embodiment of the present invention;
图4是本发明一实施方式中Html页面压缩装置的模块图。4 is a block diagram of an Html page compression device in accordance with an embodiment of the present invention.
具体实施方式detailed description
以下将结合附图所示的具体实施方式对本发明进行详细描述。但这些实施方式并不限制本发明,本领域的普通技术人员根据这些实施方式所做出的结构、方法、或功能上的变换均包含在本发明的保护范围内。The invention will be described in detail below in conjunction with the specific embodiments shown in the drawings. However, the embodiments are not intended to limit the invention, and the structural, method, or functional changes made by those skilled in the art in accordance with the embodiments are included in the scope of the present invention.
如图1所示,本发明一实施方式中,所述Html页面压缩方法包括:As shown in FIG. 1 , in an embodiment of the present invention, the Html page compression method includes:
根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段,以及将与所述Html页面对应的动态数据压缩为动态数据压缩段;Obtaining a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request, and compressing the dynamic data corresponding to the Html page into a dynamic data compression segment;
将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。Combining the static data compression segment and the dynamic data compression segment into Html page compression data, and transmitting the Html page compression data to a browser.
通过图1对应的上述流程,可以将Html页面上的静态内容预先压缩,并缓存,当接收到浏览器请求时,可只将Html页面中的动态数据的压缩,并与静态内容合并后返回,如此,与现有技术相比避免了每次请求服务器都需要进行大量的压缩,从而大大降低了服务器的计算压力。Through the above process corresponding to FIG. 1, the static content on the Html page can be pre-compressed and cached. When receiving the browser request, only the dynamic data in the Html page can be compressed and merged with the static content and returned. In this way, compared with the prior art, a large amount of compression is required for each requesting server, thereby greatly reducing the computing pressure of the server.
如图2所示,在一具体的示例中,通常地,服务器在接收到浏览器请求后,会首先经过一些公用代码,比如cookie判定。接着,判定浏览器是否接受压缩数据,如果不接受,则直接产生Html页面,并返回至浏览器。如果浏览器接受压缩数据,则可采用本发明一实施方式的Html页面压缩方法,以形成Html页面压缩数据后再返回浏览器。As shown in FIG. 2, in a specific example, typically, after receiving a browser request, the server first passes some common code, such as a cookie decision. Next, it is determined whether the browser accepts the compressed data. If not, the Html page is directly generated and returned to the browser. If the browser accepts the compressed data, the Html page compression method according to an embodiment of the present invention may be used to form the Html page compressed data and then return to the browser.
具体地,服务器接收浏览器请求,并根据浏览器请求中的http header包含的一些关键字段,比如说user-agent中的关键数据或者locale,调取缓存中相应的静态数据压缩段。 此时,存在两种可能:Specifically, the server receives the browser request, and retrieves corresponding static data compression segments in the cache according to key fields included in the http header in the browser request, such as key data or locale in the user-agent. At this point, there are two possibilities:
1)缓存中存在对应的静态数据压缩段。1) There is a corresponding static data compression segment in the cache.
此时,可获取缓存中的静态数据压缩段,并将与所述Html页面对应的动态数据压缩为动态数据压缩段。At this time, the static data compression segment in the cache may be obtained, and the dynamic data corresponding to the Html page is compressed into a dynamic data compression segment.
Html页面数据包括头部数据、中部数据和尾部数据。其中,所述的头部数据、中部数据和尾部数据可分别对应至静态数据或动态数据。The Html page data includes header data, middle data, and tail data. The head data, the middle data, and the tail data may correspond to static data or dynamic data, respectively.
进一步地,在对静态数据压缩及对动态数据压缩时具体包括:Further, when compressing static data and compressing dynamic data, the method specifically includes:
若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
这里,为了描述的简洁,以头部数据和尾部数据对应静态数据、中部数据对应动态数据为例对此时动态数据的压缩做详细的阐述:Here, for the sake of simplicity of the description, the compression of the dynamic data is described in detail by taking the header data and the tail data corresponding to the static data and the central data corresponding to the dynamic data as an example:
调用z_full_flush函数对Html页面中部数据(动态数据)进行压缩。此处,需要调用z_full_flush函数对所述中部数据进行压缩的原因是,若对于Html中的中部数据使用默认的压缩方式进行压缩,则返回的是压缩包都是完整的。例如,若直接使用JDK中的DEFLATEOutputStream来实现中部数据的压缩,那么每个压缩包都会携带完整DEFLATE头和尾信息。而对于某些浏览器来说,这些多个完整的压缩包并不能被识别。所以在java环境中,引入zlib的一个java实现版本:jzlib(http://www.jcraft.com/jzlib/,为本领域普通技术人员的公知常识,在此不再对其进行赘述),jzlib中支持压缩中的flush_mode(jzlib),故本实施方式中可相应地调用jzlib的z_full_flush函数对所述中部数据进行压缩以得到相应的动态数据压缩段。Call the z_full_flush function to compress the middle data (dynamic data) of the Html page. Here, the reason why the central data needs to be compressed by calling the z_full_flush function is that if the central data in Html is compressed using the default compression method, the returned package is complete. For example, if you directly use the DEFLATEOutputStream in the JDK to compress the central data, each compressed package will carry the full DEFLATE header and trailer information. For some browsers, these multiple complete archives are not recognized. So in the java environment, a java implementation version of zlib is introduced: jzlib (http://www.jcraft.com/jzlib/, common knowledge of those of ordinary skill in the art, which will not be described here), jzlib In the embodiment, the flush_mode (jzlib) in the compression is supported, so in the embodiment, the z_full_flush function of jzlib can be called to compress the central data to obtain a corresponding dynamic data compression segment.
具体的压缩过程中:首先在中部数据(动态数据)的字符串头部加入空字符串后进行压缩,这时,得到的压缩文件中会包含一个在所述空字符串上形成的压缩头信息;并进一步将在所述空字符串上形成的压缩头信息删除,以便于进行接着的“数据压缩段的合并”,此部分内容将在下文做详细的阐述。In the specific compression process: first, after adding an empty string to the string header of the middle data (dynamic data), the compressed file will contain a compressed header information formed on the empty string. And further deleting the compression header information formed on the empty string to facilitate the subsequent "merging of data compression segments", which will be explained in detail below.
2)缓存中不存在对应的静态数据压缩段。2) There is no corresponding static data compression segment in the cache.
这种情况下,表示缓存的数据已经过期,或者服务器启动之后,对该Html页面的请求第一次到来,所以缓存为空。此时,根据本发明的一实施方式:In this case, the cached data has expired, or the request for the Html page comes first after the server is started, so the cache is empty. At this time, according to an embodiment of the present invention:
首先接收浏览器请求,并根据所述浏览器请求中的http header生成对应的Html页面, 再将所述Html页面的静态数据和动态数据剥离,并将所述静态数据压缩为静态数据压缩段并缓存。通常地,这里利用http header中包含的关键数据,例如user-agent中的关键信息(示范性地:判定需要返回的浏览器是应用于PC还是移动电话)生成对应的Html页面。First receiving a browser request and generating a corresponding Html page according to the http header in the browser request. The static data and the dynamic data of the Html page are stripped, and the static data is compressed into a static data compression segment and cached. Typically, the key data contained in the http header is used here, such as key information in the user-agent (exemplary: determining whether the browser that needs to be returned is applied to a PC or a mobile phone) to generate a corresponding Html page.
这里,静态数据在一次压缩请求中完成压缩。为提高压缩效率,本实施方式,可在一次请求中,执行对同一Html页面数据中的多个分离的静态数据的多次压缩。并且,同步对此时压缩而成的静态数据压缩段进行存储,存储的周期可以根据Html的更新情况进行设定,以便在一个周期后,可以对该静态数据压缩段进行更新。Here, the static data is compressed in one compression request. In order to improve the compression efficiency, in the present embodiment, multiple compressions of a plurality of separate static data in the same Html page data may be performed in one request. Moreover, the static data compression segment compressed at the time is synchronized, and the storage period can be set according to the update condition of the Html, so that the static data compression segment can be updated after one cycle.
同样类似地以头部数据和尾部数据对应静态数据、中部数据对应动态数据为例对此时动态数据和静态数据的压缩做详细的阐述:Similarly, the header data and the tail data correspond to the static data, and the central data corresponds to the dynamic data as an example. The compression of the dynamic data and the static data is elaborated in this way:
调用jzlib的z_full_flush函数对Html页面头部数据(静态数据)和中部数据(动态数据)进行压缩、且调用jzlib的z_sync_flush函数对Html页面尾部数据(静态数据)进行压缩。此处,需要调用z_full_flush函数、z_sync_flush函数对相应的所述头部数据、中部数据和尾部数据进行压缩的原因是,若对于Html中的数据使用默认的压缩方式进行压缩,则返回的是每个压缩包都是完整的。例如,若直接使用JDK中的DEFLATEOutputStream来实现各部分数据的压缩,那么每个压缩包都会携带完整DEFLATE头和尾信息。而对于某些浏览器来说,这些多个完整的压缩包并不能被识别。所以在java环境中,引入zlib的一个java实现版本:jzlib,jzlib中支持压缩中的flush_mode(jzlib),故本实施方式中相应地调用z_full_flush函数和z_sync_flush函数对上述的各部分数据进行压缩以得到静态数据压缩段和动态数据压缩段。Call jzlib's z_full_flush function to compress the Html page header data (static data) and the middle data (dynamic data), and call jzlib's z_sync_flush function to compress the Html page tail data (static data). Here, the reason why the z_full_flush function and the z_sync_flush function need to be called to compress the corresponding header data, the middle data, and the tail data is that if the data in the Html is compressed using the default compression method, each of the returned The zip package is complete. For example, if you directly use the DEFLATEOutputStream in the JDK to compress each part of the data, each compressed package will carry the full DEFLATE header and trailer information. For some browsers, these multiple complete archives are not recognized. So in the java environment, a java implementation version of zlib is introduced: jzlib, jzlib supports the flush_mode (jzlib) in compression, so in this embodiment, the z_full_flush function and the z_sync_flush function are respectively called to compress the above-mentioned partial data to obtain Static data compression segment and dynamic data compression segment.
进一步地,在本实施方式中,所述“将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据”具体包括:Further, in the embodiment, the “combining the static data compression segment and the dynamic data compression segment into Html page compression data” specifically includes:
将所述静态数据压缩段与所述动态数据压缩段按照所述Html页面的原始顺序合并为Html页面压缩数据。And compressing the static data compression segment and the dynamic data compression segment into Html page compression data according to an original sequence of the Html page.
『按照Html页面的原始顺序』是指将静态数据压缩段和动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。此时,由于Html页面上的静态内容已经被预先压缩和缓存,故避免了每次请求服务器都需要进行大量的重复压缩,大大降低了服务器的计算压力。示范性地,这里的动态数据为打点数据。According to the original order of the Html page, the static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of the string. At this time, since the static content on the Html page has been pre-compressed and cached, it avoids a large amount of repeated compression every time the request server is required, which greatly reduces the computing pressure of the server. Illustratively, the dynamic data here is dot data.
进一步地,为了使更多浏览器可识别该Html页面压缩数据,所述Html页面压缩数据中,通过一个压缩头信息和一个压缩尾信息将所述静态数据压缩段和所述动态数据压 缩段封装。Further, in order to enable more browsers to recognize the Html page compressed data, in the Html page compressed data, the static data compressed segment and the dynamic data are compressed by a compressed header information and a compressed tail information. Shrink section package.
如图3所示,以一个Html页面包括两个静态数据压缩段:DEFLATE Data A(头部数据压缩段)、DEFLATE Data C(尾部数据压缩段)和一个动态数据压缩段:DEFLATE Data B(中部数据压缩段)为例。DEFLATE Data A由z_full_flush函数压缩而成,其包含一个DEFLATE Header,DEFLATE Data C由z_sync_flush函数压缩而成,其包含一个DEFLATE Tail。DEFLATE Data B由z_full_flush函数压缩而成,在DEFLATE Data B的压缩过程中,在其对应的字符串头部插入空字符串,并在压缩后再将在该空字符串上形成的压缩头信息删除。如此,DEFLATE Data A、DEFLATE Data B、DEFLATE Data C可以顺序合并成一个完整的Html页面压缩数据。As shown in Figure 3, one Html page includes two static data compression segments: DEFLATE Data A (head data compression segment), DEFLATE Data C (tail data compression segment), and a dynamic data compression segment: DEFLATE Data B (middle Data compression section) as an example. DEFLATE Data A is compressed by the z_full_flush function, which contains a DEFLATE Header, which is compressed by the z_sync_flush function and contains a DEFLATE Tail. DEFLATE Data B is compressed by the z_full_flush function. In the compression process of DEFLATE Data B, an empty string is inserted in the corresponding string header, and the compression header information formed on the empty string is deleted after compression. . Thus, DEFLATE Data A, DEFLATE Data B, and DEFLATE Data C can be combined in sequence to form a complete Html page compression data.
当然,在示范性的一替换的实施方式中,DEFLATE Data B也可以是由z_sync_flush函数压缩而成,相应地,在DEFLATE Data B的压缩过程中,在其对应的字符串尾部插入空字符串,并在压缩后再将在该空字符串上形成的压缩尾信息删除。如此,同样可以将DEFLATE Data A、DEFLATE Data B、DEFLATE Data C顺序合并成一个完整的Html页面压缩数据。Of course, in an exemplary alternative embodiment, DEFLATE Data B may also be compressed by the z_sync_flush function, and correspondingly, in the compression process of DEFLATE Data B, an empty string is inserted at the end of its corresponding string. And after compression, the compressed tail information formed on the empty string is deleted. In this way, DEFLATE Data A, DEFLATE Data B, and DEFLATE Data C can also be combined into one complete Html page compression data.
在本实施方式中,每个静态数据压缩段均包括字典数据,而并非使用第一压缩段的字典数据,以可单独进行解压缩。In the present embodiment, each static data compression segment includes dictionary data instead of the dictionary data of the first compressed segment, so that decompression can be performed separately.
最后,再将上述的Html页面压缩数据发送至浏览器。在此过程中,先配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式,再将Html页面压缩数据放入response的缓冲区。缓冲区将Html页面压缩数据再最终返回至浏览器以完成整个Html页面发送至浏览器的过程。Finally, the above Html page compression data is sent to the browser. In this process, first configure the Http response header to inform the browser of the compression format of the Html page compressed data it receives, and then put the Html page compressed data into the response buffer. The buffer compresses the Html page and finally returns it to the browser to complete the process of sending the entire Html page to the browser.
在一个本发明Html页面压缩方法的java版方案实现示例中,预先生成了a_html和c_html,这两个页面中间还有一部分动态数据。先把a_html和c_html压缩并放入缓存,然后每次请求来时从缓存调取该静态压缩数据,而缓存如果没有,则重新动态生成静态压缩数据;接着产生动态数据并压缩,然后设置HTTP response header,最后按照页面的原始顺序将压缩包刷入response的缓冲区。In an example implementation of the java version of the Html page compression method of the present invention, a_html and c_html are generated in advance, and some dynamic data is also included between the two pages. First compress a_html and c_html into the cache, then retrieve the static compressed data from the cache each time the request comes, and if not, re-generate the static compressed data dynamically; then generate dynamic data and compress, then set the HTTP response Header, and finally the compressed package is flushed into the response buffer according to the original order of the page.
值得注意的是,在压缩动态数据的过程中,无需每次都创建ZStream,只需要为每条线程创建一次,即可重复使用。通过这样的方式,一个数百KB的页面,少量的动态数据将会被实施压缩,绝大部分的数据会被预先压缩之后,后续请求过来无需再次压缩,成功地避免了很多重复计算。It's worth noting that in the process of compressing dynamic data, you don't need to create a ZStream every time. You only need to create it once for each thread and you can reuse it. In this way, a few hundred KB of pages, a small amount of dynamic data will be compressed, most of the data will be pre-compressed, subsequent requests do not need to be compressed again, successfully avoiding a lot of double counting.
如图4所示,在本发明一实施方式中,所述Html页面压缩装置100包括调取模块 10、压缩模块20、以及处理模块30。As shown in FIG. 4, in an embodiment of the present invention, the Html page compression apparatus 100 includes a retrieval module. 10. The compression module 20 and the processing module 30.
所述调取模块10用于根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段;The retrieving module 10 is configured to obtain a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request;
所述压缩模块20用于将与所述Html页面对应的动态数据压缩为动态数据压缩段;The compression module 20 is configured to compress dynamic data corresponding to the Html page into a dynamic data compression segment;
所述处理模块30用于将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。The processing module 30 is configured to merge the static data compression segment and the dynamic data compression segment into Html page compression data, and send the Html page compression data to a browser.
在一具体的示例中,通常地,服务器在接收到浏览器请求后,会首先经过一些公用代码,比如cookie判定。接着,判定浏览器是否接受压缩数据,如果不接受,则直接产生Html页面,并返回至浏览器。如果浏览器接受压缩数据,则可采用本发明一实施方式的Html页面压缩装置,以形成Html页面压缩数据后再返回浏览器。In a specific example, typically, after receiving a browser request, the server first passes some common code, such as a cookie decision. Next, it is determined whether the browser accepts the compressed data. If not, the Html page is directly generated and returned to the browser. If the browser accepts the compressed data, the Html page compression device according to an embodiment of the present invention may be used to form the Html page compressed data and then return to the browser.
具体地,服务器接收浏览器请求,并根据浏览器请求中的http header包含的一些关键字段,比如说user-agent中的关键数据或者locale,调取缓存中相应的静态数据压缩段。此时,存在两种可能:Specifically, the server receives the browser request, and retrieves corresponding static data compression segments in the cache according to key fields included in the http header in the browser request, such as key data or locale in the user-agent. At this point, there are two possibilities:
1)缓存中存在对应的静态数据压缩段。1) There is a corresponding static data compression segment in the cache.
此时,可获取缓存中的静态数据压缩段,并将与所述Html页面对应的动态数据压缩为动态数据压缩段。At this time, the static data compression segment in the cache may be obtained, and the dynamic data corresponding to the Html page is compressed into a dynamic data compression segment.
Html页面数据包括头部数据、中部数据和尾部数据。其中,所述的头部数据、中部数据和尾部数据可分别对应至静态数据或动态数据。The Html page data includes header data, middle data, and tail data. The head data, the middle data, and the tail data may correspond to static data or dynamic data, respectively.
所述压缩模块20用于:The compression module 20 is configured to:
若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
这里,为了描述的简洁,以头部数据和尾部数据对应静态数据、中部数据对应动态数据为例对此时动态数据的压缩做详细的阐述:Here, for the sake of simplicity of the description, the compression of the dynamic data is described in detail by taking the header data and the tail data corresponding to the static data and the central data corresponding to the dynamic data as an example:
压缩模块20调用z_full_flush函数对Html页面中部数据(动态数据)进行压缩。此处,需要调用z_full_flush函数对所述中部数据进行压缩的原因是,若对于Html中的中部数据使用默认的压缩方式进行压缩,则返回的是压缩包都是完整的。例如,若直接使用JDK中的DEFLATEOutputStream来实现中部数据的压缩,那么每个压缩包都会携带完整DEFLATE头和尾信息。而对于某些浏览器来说,这些多个完整的压缩包并不能被 识别。所以在java环境中,引入zlib的一个java实现版本:jzlib(http://www.jcraft.com/jzlib/,为本领域普通技术人员的公知常识,在此不再对其进行赘述),jzlib中支持压缩中的flush_mode(jzlib),故本实施方式中可相应地调用jzlib的z_full_flush函数对所述中部数据进行压缩以得到相应的动态数据压缩段。The compression module 20 calls the z_full_flush function to compress the middle data (dynamic data) of the Html page. Here, the reason why the central data needs to be compressed by calling the z_full_flush function is that if the central data in Html is compressed using the default compression method, the returned package is complete. For example, if you directly use the DEFLATEOutputStream in the JDK to compress the central data, each compressed package will carry the full DEFLATE header and trailer information. For some browsers, these multiple complete archives cannot be Identification. So in the java environment, a java implementation version of zlib is introduced: jzlib (http://www.jcraft.com/jzlib/, common knowledge of those of ordinary skill in the art, which will not be described here), jzlib In the embodiment, the flush_mode (jzlib) in the compression is supported, so in the embodiment, the z_full_flush function of jzlib can be called to compress the central data to obtain a corresponding dynamic data compression segment.
具体的压缩过程中:处理模块30首先在中部数据(动态数据)的字符串头部加入空字符串后供压缩模块20进行压缩,这时,得到的压缩文件中会包含一个在所述空字符串上形成的压缩头信息;处理模块30进一步将在所述空字符串上形成的压缩头信息删除,以便于进行接着的“数据压缩段的合并”,此部分内容将在下文做详细的阐述。During the specific compression process, the processing module 30 first adds an empty string to the string header of the middle data (dynamic data) for compression by the compression module 20. At this time, the obtained compressed file will include a null character in the compressed file. The compression header information formed on the string; the processing module 30 further deletes the compression header information formed on the empty character string to facilitate the subsequent "merging of data compression segments", which will be explained in detail below. .
2)缓存中不存在对应的静态数据压缩段。2) There is no corresponding static data compression segment in the cache.
这种情况下,表示缓存的数据已经过期,或者服务器启动之后,对该Html页面的请求第一次到来,所以缓存为空。此时,根据本发明的一实施方式:In this case, the cached data has expired, or the request for the Html page comes first after the server is started, so the cache is empty. At this time, according to an embodiment of the present invention:
处理模块30用于首先接收浏览器请求,并根据所述浏览器请求中的http header生成对应的Html页面,再将所述Html页面的静态数据和动态数据剥离,压缩模块20用于将所述静态数据压缩为静态数据压缩段并缓存。通常地,这里利用http header中包含的关键数据,例如user-agent中的关键信息(示范性地:判定需要返回的浏览器是应用于PC还是移动电话)生成对应的Html页面。The processing module 30 is configured to first receive a browser request, generate a corresponding Html page according to the http header in the browser request, and then strip the static data and the dynamic data of the Html page, and the compression module 20 is configured to: Static data is compressed into static data compression segments and cached. Typically, the key data contained in the http header is used here, such as key information in the user-agent (exemplary: determining whether the browser that needs to be returned is applied to a PC or a mobile phone) to generate a corresponding Html page.
这里,静态数据在一次压缩请求中对多个静态完成压缩。为提高效率,本实施方式中,可在一次压缩请求中,执行对同一Html页面数据中的多个分离的静态数据的多次压缩。并且,存储模块40同步对此时压缩而成的静态数据压缩段进行存储,存储的周期可以根据Html的更新情况进行设定,以便在一个周期后,可以对该静态数据压缩段进行更新。Here, the static data is compressed for multiple statics in one compression request. In order to improve efficiency, in the present embodiment, multiple compression of a plurality of separate static data in the same Html page data may be performed in one compression request. Moreover, the storage module 40 synchronizes the static data compression segment compressed at this time, and the storage period can be set according to the update condition of the Html, so that the static data compression segment can be updated after one cycle.
同样类似地以头部数据和尾部数据对应静态数据、中部数据对应动态数据为例对此时动态数据和静态数据的压缩做详细的阐述:Similarly, the header data and the tail data correspond to the static data, and the central data corresponds to the dynamic data as an example. The compression of the dynamic data and the static data is elaborated in this way:
调用jzlib的z_full_flush函数对Html页面头部数据(静态数据)和中部数据(动态数据)进行压缩、且调用jzlib的z_sync_flush函数对Html页面尾部数据(静态数据)进行压缩。此处,需要调用z_full_flush函数、z_sync_flush函数对相应的所述头部数据、中部数据和尾部数据进行压缩的原因是,若对于Html中的数据使用默认的压缩方式进行压缩,则返回的是每个压缩包都是完整的。例如,若直接使用JDK中的DEFLATEOutputStream来实现各部分数据的压缩,那么每个压缩包都会携带完整DEFLATE头和尾信息。而对于某些浏览器来说,这些多个完整的压缩包并不能被识别。 所以在java环境中,引入zlib的一个java实现版本:jzlib,jzlib中支持压缩中的flush_mode(jzlib),故本实施方式中相应地调用z_full_flush函数和z_sync_flush函数对上述的各部分数据进行压缩以得到静态数据压缩段和动态数据压缩段。Call jzlib's z_full_flush function to compress the Html page header data (static data) and the middle data (dynamic data), and call jzlib's z_sync_flush function to compress the Html page tail data (static data). Here, the reason why the z_full_flush function and the z_sync_flush function need to be called to compress the corresponding header data, the middle data, and the tail data is that if the data in the Html is compressed using the default compression method, each of the returned The zip package is complete. For example, if you directly use the DEFLATEOutputStream in the JDK to compress each part of the data, each compressed package will carry the full DEFLATE header and trailer information. For some browsers, these multiple complete archives are not recognized. So in the java environment, a java implementation version of zlib is introduced: jzlib, jzlib supports the flush_mode (jzlib) in compression, so in this embodiment, the z_full_flush function and the z_sync_flush function are respectively called to compress the above-mentioned partial data to obtain Static data compression segment and dynamic data compression segment.
进一步地,在本实施方式中,处理模块30还用于:Further, in this embodiment, the processing module 30 is further configured to:
将所述静态数据压缩段与所述动态数据压缩段按照所述Html页面的原始顺序合并为Html页面压缩数据。And compressing the static data compression segment and the dynamic data compression segment into Html page compression data according to an original sequence of the Html page.
『按照Html页面的原始顺序』是指处理模块30将静态数据压缩段和动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。此时,由于Html页面上的静态内容已经被预先压缩和缓存,故避免了每次请求服务器都需要进行大量的重复压缩,大大降低了服务器的计算压力。示范性地,这里的动态数据为打点数据。According to the original order of the Html page, the processing module 30 assembles the static data compression segment and the dynamic data compression segment into Html page compression data in the order of the string. At this time, since the static content on the Html page has been pre-compressed and cached, it avoids a large amount of repeated compression every time the request server is required, which greatly reduces the computing pressure of the server. Illustratively, the dynamic data here is dot data.
进一步地,为了使更多浏览器可识别该Html页面压缩数据,在Html页面压缩数据中,是通过一个压缩头信息和一个压缩尾信息将静态数据压缩段和动态数据压缩段封装。Further, in order to enable more browsers to recognize the Html page compressed data, in the Html page compressed data, the static data compressed segment and the dynamic data compressed segment are encapsulated by a compressed header information and a compressed tail information.
如图3所示,以一个Html页面包括两个静态数据压缩段:DEFLATE Data A(头部数据压缩段)、DEFLATE Data C(尾部数据压缩段)和一个动态数据压缩段:DEFLATE Data B(中部数据压缩段)为例。DEFLATE Data A由z_full_flush函数压缩而成,其包含一个DEFLATE Header,DEFLATE Data C由z_sync_flush函数压缩而成,其包含一个DEFLATE Tail。DEFLATE Data B由z_full_flush函数压缩而成,在DEFLATE Data B的压缩过程中,在其对应的字符串头部插入空字符串,并在压缩后再将在该空字符串上形成的压缩头信息删除。如此,DEFLATE Data A、DEFLATE Data B、DEFLATE Data C可以顺序合并成一个完整的Html页面压缩数据。As shown in Figure 3, one Html page includes two static data compression segments: DEFLATE Data A (head data compression segment), DEFLATE Data C (tail data compression segment), and a dynamic data compression segment: DEFLATE Data B (middle Data compression section) as an example. DEFLATE Data A is compressed by the z_full_flush function, which contains a DEFLATE Header, which is compressed by the z_sync_flush function and contains a DEFLATE Tail. DEFLATE Data B is compressed by the z_full_flush function. In the compression process of DEFLATE Data B, an empty string is inserted in the corresponding string header, and the compression header information formed on the empty string is deleted after compression. . Thus, DEFLATE Data A, DEFLATE Data B, and DEFLATE Data C can be combined in sequence to form a complete Html page compression data.
当然,在示范性的一替换的实施方式中,DEFLATE Data B也可以是由压缩模块20调用z_sync_flush函数压缩而成,相应地,在DEFLATE Data B的压缩过程中,处理模块30在其对应的字符串尾部插入空字符串,并在压缩后再将在该空字符串上形成的压缩尾信息删除。如此,同样可以将DEFLATE Data A、DEFLATE Data B、DEFLATE Data C顺序合并成一个完整的Html页面压缩数据。Of course, in an exemplary alternative embodiment, the DEFLATE Data B may also be compressed by the compression module 20 by calling the z_sync_flush function. Accordingly, in the compression process of the DEFLATE Data B, the processing module 30 is in its corresponding character. An empty string is inserted at the end of the string, and the compressed tail information formed on the empty string is deleted after compression. In this way, DEFLATE Data A, DEFLATE Data B, and DEFLATE Data C can also be combined into one complete Html page compression data.
在本实施方式中,每个静态数据压缩段均包括字典数据,而并非使用第一压缩段的字典数据,以可单独进行解压缩。In the present embodiment, each static data compression segment includes dictionary data instead of the dictionary data of the first compressed segment, so that decompression can be performed separately.
最后,处理模块30再将上述的Html页面压缩数据发送至浏览器。在此过程中,配置模块50首先为Html页面压缩数据配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式,处理模块30再将Html页面压缩数据放入response的缓 冲区。缓冲区将压缩Html页面压缩数据再最终返回至浏览器以完成整个Html页面发送至浏览器的过程。Finally, the processing module 30 sends the Html page compression data to the browser. In this process, the configuration module 50 first configures an Http response header for the Html page compression data to notify the browser of the compression format of the Html page compressed data received by the browser, and the processing module 30 then puts the Html page compressed data into the response. Punching area. The buffer will compress the Html page to compress the data and finally return to the browser to complete the process of sending the entire Html page to the browser.
需要说明的是,上述的调取模块10、压缩模块20、处理模块30、存储模块40、和配置模块50都为根据逻辑功能的一种示范性的划分,实际的应用中,可能是由代理服务器、或应用服务器、或代理服务器和应用服务器协同实现上述实施方式中各模块的功能,而上述的各模块也可以相应地被视为共同构成所述代理服务器和应用服务器的至少部分。It should be noted that the above-mentioned retrieving module 10, compression module 20, processing module 30, storage module 40, and configuration module 50 are all exemplary partitions according to logical functions. In actual applications, agents may be used. The server, or the application server, or the proxy server and the application server cooperate to implement the functions of the modules in the above embodiments, and the above-described modules may be correspondingly considered to constitute at least part of the proxy server and the application server.
综上所述,本发明的Html页面压缩方法及装置可以将Html页面上的静态内容预先压缩,并缓存,当接收到浏览器请求时,可只将Html页面中的动态数据的压缩,并与静态内容合并后返回,如此,避免了每次请求服务器都需要进行大量的压缩,大大降低了服务器的计算压力。In summary, the Html page compression method and apparatus of the present invention can pre-compress and cache the static content on the Html page, and when receiving the browser request, can only compress the dynamic data in the Html page, and Static content is returned after merging. In this way, it avoids a lot of compression every time the request server needs, which greatly reduces the computing pressure of the server.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的装置,装置和模块的具体工作过程,可以参考前述方法实施方式中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-mentioned apparatus, device and module can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
综上所述,本发明的Html页面压缩方法及装置可以将Html页面上的静态内容预先压缩,并缓存,当接收到浏览器请求时,可只将Html页面中的动态数据的压缩,并与静态内容合并后返回,如此,避免了每次请求服务器都需要进行大量的压缩,大大降低了服务器的计算压力。In summary, the Html page compression method and apparatus of the present invention can pre-compress and cache the static content on the Html page, and when receiving the browser request, can only compress the dynamic data in the Html page, and Static content is returned after merging. In this way, it avoids a lot of compression every time the request server needs, which greatly reduces the computing pressure of the server.
在本发明所提供的几个实施方式中,应该理解到,所揭露的装置,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施方式仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个模块或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或模块的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus, apparatus, and method may be implemented in other manners. For example, the device implementations described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be another division manner, for example, multiple modules or components may be combined or It can be integrated into another device, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or module, and may be electrical, mechanical or otherwise.
所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施方式方案的目的。The modules described as separate components may or may not be physically separated. The components displayed as modules may or may not be physical modules, that is, may be located in one place, or may be distributed to multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
另外,在本发明各个实施方式中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以2个或2个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用硬件加软件功能模块的形式实现。 In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of hardware plus software function modules.
上述以软件功能模块的形式实现的集成的模块,可以存储在一个计算机可读取存储介质中。上述软件功能模块存储在一个存储介质中,包括若干指令用以使得一台计算机装置(可以是个人计算机,服务器,或者网络装置等)或处理器(processor)执行本发明各个实施方式所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The above-described integrated modules implemented in the form of software function modules can be stored in a computer readable storage medium. The software function module described above is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the method of various embodiments of the present invention. Part of the steps. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .
最后应说明的是:以上实施方式仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施方式对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施方式所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施方式技术方案的精神和范围。 Finally, it should be noted that the above embodiments are only for explaining the technical solutions of the present invention, and are not intended to be limiting; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that Modifications of the technical solutions described in the foregoing embodiments, or equivalents of the technical features of the embodiments of the present invention, are not to be construed as a departure from the spirit and scope of the embodiments of the present invention.

Claims (20)

  1. 一种Html页面压缩方法,其特征在于,所述方法包括:An Html page compression method, the method comprising:
    根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段,以及将与所述Html页面对应的动态数据压缩为动态数据压缩段;Obtaining a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request, and compressing the dynamic data corresponding to the Html page into a dynamic data compression segment;
    将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。Combining the static data compression segment and the dynamic data compression segment into Html page compression data, and transmitting the Html page compression data to a browser.
  2. 根据权利要求1所述的Html页面压缩方法,其特征在于,将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,具体包括:The Html page compression method according to claim 1, wherein the static data compression segment and the dynamic data compression segment are combined into Html page compression data, which specifically includes:
    将所述静态数据压缩段与所述动态数据压缩段按照所述Html页面的原始顺序合并为Html页面压缩数据。And compressing the static data compression segment and the dynamic data compression segment into Html page compression data according to an original sequence of the Html page.
  3. 根据权利要求1或2所述的Html页面压缩方法,其特征在于,所述Html页面压缩数据中,通过一个压缩头信息和一个压缩尾信息将所述静态数据压缩段和所述动态数据压缩段封装。The Html page compression method according to claim 1 or 2, wherein in the Html page compression data, the static data compression segment and the dynamic data compression segment are compressed by a compression header information and a compressed tail information. Package.
  4. 根据权利要求1所述的Html页面压缩方法,其特征在于,在获取静态数据压缩段及压缩动态数据前,所述方法包括:The Html page compression method according to claim 1, wherein before the obtaining the static data compression segment and compressing the dynamic data, the method comprises:
    接收浏览器请求;Receiving a browser request;
    根据所述浏览器请求中的http header生成对应的Html页面;Generating a corresponding Html page according to the http header in the browser request;
    将所述Html页面的静态数据和动态数据剥离;Stripping static data and dynamic data of the Html page;
    将所述静态数据压缩为静态数据压缩段并缓存。The static data is compressed into a static data compression segment and cached.
  5. 根据权利要求4所述的Html页面压缩方法,其特征在于,将所述静态数据压缩为静态数据压缩段并缓存,具体包括:The Html page compression method according to claim 4, wherein the static data is compressed into a static data compression segment and cached, and specifically includes:
    将所述静态数据在一次压缩请求中完成压缩,以生成至少一个静态数据压缩段,并存储所述至少一个静态数据压缩段。The static data is compressed in a compression request to generate at least one static data compression segment, and the at least one static data compression segment is stored.
  6. 根据权利要求4所述的Html页面压缩方法,其特征在于,所述方法在对静态数据压缩及对动态数据压缩时,具体包括:The Html page compression method according to claim 4, wherein when the method compresses the static data and compresses the dynamic data, the method specifically includes:
    若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
    调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
    若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
  7. 根据权利要求6所述的Html页面压缩方法,其特征在于,调用z_full_flush函 数对Html页面的中部数据进行压缩,具体包括:The Html page compression method according to claim 6, wherein the z_full_flush function is called. The number of the central data of the Html page is compressed, including:
    在Html页面中部数据的字符串头部加入空字符串后进行压缩;Compressing after adding an empty string to the string header of the data in the middle of the Html page;
    将在所述空字符串上形成的压缩头信息删除。The compression header information formed on the empty string is deleted.
  8. 根据权利要求1所述的Html页面压缩方法,其特征在于,每个静态数据压缩段均包括字典数据,以可单独进行解压缩。The Html page compression method according to claim 1, wherein each of the static data compression segments includes dictionary data so as to be decompressible separately.
  9. 根据权利要求2所述的Html页面压缩方法,其特征在于,按照所述Html页面的原始顺序合并为Html页面压缩数据,具体包括:The Html page compression method according to claim 2, wherein the Html page compression data is merged according to the original order of the Html page, and specifically includes:
    将所述静态数据压缩段和所述动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。The static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of a character string.
  10. 根据权利要求1所述的Html页面压缩方法,其特征在于,所述方法还包括:The Html page compression method according to claim 1, wherein the method further comprises:
    配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式。Configure the Http response header to inform the browser of the compression format of the Html page compressed data it receives.
  11. 一种Html页面压缩装置,其特征在于,所述装置包括:An Html page compression device, characterized in that the device comprises:
    调取模块,用于根据浏览器请求中的http header获取缓存中对应的Html页面的静态数据压缩段;The calling module is configured to obtain a static data compression segment of the corresponding Html page in the cache according to the http header in the browser request;
    压缩模块,用于将与所述Html页面对应的动态数据压缩为动态数据压缩段;a compression module, configured to compress dynamic data corresponding to the Html page into a dynamic data compression segment;
    处理模块,用于将所述静态数据压缩段和所述动态数据压缩段合并为Html页面压缩数据,并将所述Html页面压缩数据发送至浏览器。And a processing module, configured to merge the static data compression segment and the dynamic data compression segment into Html page compression data, and send the Html page compression data to a browser.
  12. 根据权利要求11所述的Html页面压缩装置,其特征在于,所述处理模块用于:The Html page compression apparatus according to claim 11, wherein the processing module is configured to:
    将所述静态数据压缩段与所述动态数据段按照所述Html页面的原始顺序合并为Html页面压缩数据。The static data compression segment and the dynamic data segment are merged into Html page compressed data according to the original order of the Html page.
  13. 根据权利要求11或12所述的Html页面压缩装置,其特征在于,所述Html页面压缩数据中,通过一个压缩头信息和一个压缩尾信息将所述静态数据压缩段和所述动态数据压缩段封装。The Html page compression apparatus according to claim 11 or 12, wherein in the Html page compressed data, the static data compressed segment and the dynamic data compressed segment are compressed by a compressed header information and a compressed tail information. Package.
  14. 根据权利要求11所述的Html页面压缩装置,其特征在于,所述处理模块还用于:The Html page compression device according to claim 11, wherein the processing module is further configured to:
    接收浏览器请求;Receiving a browser request;
    根据所述浏览器请求中的http header生成对应的Html页面;Generating a corresponding Html page according to the http header in the browser request;
    将所述Html页面的静态数据和动态数据剥离;所述压缩模块还用于:Separating static data and dynamic data of the Html page; the compression module is further configured to:
    将所述静态数据压缩为静态数据压缩段并缓存。The static data is compressed into a static data compression segment and cached.
  15. 根据权利要求14所述的Html页面压缩装置,其特征在于,所述压缩模块用于 将所述静态数据在一次压缩请求中完成压缩,以生成至少一个静态数据压缩段,所述装置还包括存储模块,所述存储模块用于:The Html page compression apparatus according to claim 14, wherein said compression module is used for Compressing the static data in a compression request to generate at least one static data compression segment, the device further comprising a storage module, the storage module is configured to:
    存储所述至少一个静态数据压缩段。Storing the at least one static data compression segment.
  16. 根据权利要求14所述的Html页面压缩装置,其特征在于,所述压缩模块用于:The Html page compression apparatus according to claim 14, wherein the compression module is configured to:
    若所述静态数据或所述动态数据为Html页面的头部数据或中部数据,则If the static data or the dynamic data is the header data or the middle data of the Html page, then
    调用z_full_flush函数进行压缩;Call the z_full_flush function to compress;
    若所述静态数据或所述动态数据为Html页面的尾部数据,则调用z_sync_flush函数进行压缩。If the static data or the dynamic data is the tail data of the Html page, the z_sync_flush function is called to perform compression.
  17. 根据权利要求16所述的Html页面压缩装置,其特征在于,所述处理模块用于:The Html page compression apparatus according to claim 16, wherein the processing module is configured to:
    在Html页面中部数据的字符串头部加入空字符串后供所述压缩模块进行压缩;Adding an empty string to the string header of the data in the middle of the Html page for compression by the compression module;
    将在所述空字符串上形成的压缩头信息删除。The compression header information formed on the empty string is deleted.
  18. 根据权利要求11所述的Html页面压缩装置,其特征在于,每个静态数据压缩段均包括字典数据,以可单独进行解压缩。The Html page compression apparatus according to claim 11, wherein each of the static data compression sections includes dictionary data so as to be decompressible separately.
  19. 根据权利要求12所述的Html页面压缩装置,其特征在于,所述处理模块用于:The Html page compression apparatus according to claim 12, wherein the processing module is configured to:
    将所述静态数据压缩段和所述动态数据压缩段按照字符串的顺序拼装为Html页面压缩数据。The static data compression segment and the dynamic data compression segment are assembled into Html page compression data in the order of a character string.
  20. 根据权利要求11所述的Html页面压缩装置,其特征在于,所述装置还包括配置模块,用于:The Html page compression device according to claim 11, wherein the device further comprises a configuration module, configured to:
    配置Http response header,以通知浏览器其接收的Html页面压缩数据的压缩格式。 Configure the Http response header to inform the browser of the compression format of the Html page compressed data it receives.
PCT/CN2016/075942 2015-03-17 2016-03-09 Html page compression method and device WO2016146009A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510115508.0A CN106033448A (en) 2015-03-17 2015-03-17 Method and device for compressing Html page
CN201510115508.0 2015-03-17

Publications (1)

Publication Number Publication Date
WO2016146009A1 true WO2016146009A1 (en) 2016-09-22

Family

ID=56918334

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/075942 WO2016146009A1 (en) 2015-03-17 2016-03-09 Html page compression method and device

Country Status (2)

Country Link
CN (1) CN106033448A (en)
WO (1) WO2016146009A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115065725A (en) * 2022-05-12 2022-09-16 北京奇艺世纪科技有限公司 Data processing method and device, electronic equipment and storage medium

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106790662A (en) * 2017-01-20 2017-05-31 济南浪潮高新科技投资发展有限公司 A kind of HTTP data compression method of use key frame compression
CN113364508B (en) * 2021-04-30 2022-08-16 深圳震有科技股份有限公司 Voice data transmission control method, system and equipment
CN113518088B (en) * 2021-07-12 2023-07-07 北京百度网讯科技有限公司 Data processing method, device, server, client and medium
CN113612516B (en) * 2021-07-13 2023-05-12 深圳震有科技股份有限公司 Compression test method, system and equipment for satellite communication data packet

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7484007B2 (en) * 2002-02-01 2009-01-27 Codekko Inc. System and method for partial data compression and data transfer
CN102298630A (en) * 2011-08-30 2011-12-28 国电南瑞科技股份有限公司 Line style-based process data lossy compression method
CN102375884A (en) * 2011-10-21 2012-03-14 北京百度网讯科技有限公司 Method and device for data compression for page access object
CN104283777A (en) * 2013-07-03 2015-01-14 华为技术有限公司 Message compression method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7484007B2 (en) * 2002-02-01 2009-01-27 Codekko Inc. System and method for partial data compression and data transfer
CN102298630A (en) * 2011-08-30 2011-12-28 国电南瑞科技股份有限公司 Line style-based process data lossy compression method
CN102375884A (en) * 2011-10-21 2012-03-14 北京百度网讯科技有限公司 Method and device for data compression for page access object
CN104283777A (en) * 2013-07-03 2015-01-14 华为技术有限公司 Message compression method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115065725A (en) * 2022-05-12 2022-09-16 北京奇艺世纪科技有限公司 Data processing method and device, electronic equipment and storage medium
CN115065725B (en) * 2022-05-12 2024-01-12 北京奇艺世纪科技有限公司 Data processing method, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN106033448A (en) 2016-10-19

Similar Documents

Publication Publication Date Title
WO2016146009A1 (en) Html page compression method and device
CN103392179B (en) Obtain method and device, browser and the mobile terminal of page resource
US9077681B2 (en) Page loading optimization using page-maintained cache
US9582600B1 (en) Cloud browser DOM-based client
US9594477B1 (en) Using deep links to restore interactive state of a web page
KR20040104515A (en) Method and apparatus for generating graphical and media displays at a client
KR20050043689A (en) Optimizing file replication using binary comparisons
WO2017114190A1 (en) File uploading processing method and device
CN103532984B (en) Data transmission method, device and system of websocket protocol
CN106453572B (en) Method and system based on Cloud Server synchronous images
WO2017174026A1 (en) Client connection method and system
CN109714406B (en) Method and equipment for processing resource description file and acquiring page resource
CN113992738A (en) Reverse proxy method, device, equipment and storage medium based on micro service gateway
CN111756847B (en) Method and device for supporting https protocol by website
CN109885347B (en) Method, device, terminal, system and storage medium for acquiring configuration data
US8583829B2 (en) Semantic-based lossy compression
US10749926B2 (en) Proxy for modifying HTTP messages to comply with browser
CN107368484A (en) Compression method and device, the acquisition methods and device of the static resource file of webpage
CN107092529B (en) OLAP service method, device and system
CN109766347B (en) Data updating method, device, system, computer equipment and storage medium
JP3916219B2 (en) Link destination compression system
CN114996361A (en) Data processing method and system
CN111063347B (en) Real-time voice recognition method, server and client
US10841405B1 (en) Data compression of table rows
CN113542335A (en) Information sharing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16764190

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16764190

Country of ref document: EP

Kind code of ref document: A1