Browser script caching method and system

A caching system and browser technology, applied in the computer field, can solve problems such as wasting traffic and affecting page opening speed, and achieve the effects of improving loading speed, reducing script loading, and better control

Inactive Publication Date: 2017-01-04
FUJIAN TQ DIGITAL
View PDF8 Cites 4 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0004] However, with the above method, the browser will reload the script every time it is refreshed, which seriously affects the page opening speed and wastes traffic

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Browser script caching method and system
  • Browser script caching method and system
  • Browser script caching method and system

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0074]请参照图3,本发明的实施例一为:

[0075]一种浏览器脚本的缓存方法,包括:

[0076]浏览器首次加载页面时,即本地存储中没有脚本时,浏览器以Ajax的方式向服务器发送请求,服务器根据Ajax的请求将对应的脚本发送至浏览器;

[0077]浏览器将所述脚本按照Ajax的请求的顺序以动态解释的方式逐个执行;例如,Ajax的请求为将a.js、b.js、c.js三个脚本依次进行加载,则浏览器对该三个脚本进行动态解释时也按照a.js、b.js、c.js的顺序;具体的,对每个脚本逐个执行的方式如下:浏览器先调用eval函数对脚本进行动态解释,并通过异常检测判断脚本是否正确执行,若果是则判定脚本执行成功,否则判定脚本执行失败;

[0078]将执行成功的脚本直接存储至本地存储中;

[0079]将执行失败的脚本采用base64算法进行编码后存储至本地存储中;上述存储时将脚本以地址为索引存储至本地存储中。

[0080]接下来浏览器每次加载页面时,请求脚本之前都先判断本地存储中是否存在需要请求的脚本,若是则直接从本地存储中获取脚本,不再发送Ajax的请求;若本地存储中没有需要请求的脚本,以Ajax的方式向服务器发送请求,从服务器获取脚本。

[0081]上述从本地存储中获取脚本后,先判断获取的脚本是否支持eval函数进行动态解释,若支持则将该脚本从本地存储中读取出来,调用eval函数进行动态解释;若不支持,则通过动态创建srcipt标签将src属性设置为data类型,传入该脚本对应的base64编码后的脚本,对编码后的脚本进行动态加载。

Embodiment 2

[0082]请参照图4,本发明的实施例二为:

[0083]一种与上述实施例一所述的浏览器脚本的缓存方法对应的系统,包括:

[0084]第一判断模块5,用于判断本地存储中是否存在需要请求的脚本;

[0085]第一加载模块6,用于若是,则从本地存储中获取所述需要请求的脚本;

[0086]若否,进入请求模块1,用于浏览器根据Ajax的请求获取脚本;

[0087]执行模块2,用于将所述脚本按照Ajax的请求的顺序以动态解释的方式逐个执行;所述执行模块2包括:第一调用模块21,用于调用eval函数执行所述脚本;判定模块22,用于若所述脚本正确执行,则判定所述脚本执行成功;若所述脚本执行异常,则判定所述脚本执行失败;

[0088]存储模块3,用于将执行成功的脚本存储至本地存储中;

[0089]编码模块4,用于将执行失败的脚本采用base64算法进行编码后存储至本地存储中。

[0090]具体的,上述第一加载模块6包括:

[0091]第二判断模块61,用于执行本地存储的脚本时,判断所述脚本是否支持eval函数进行动态解释;

[0092]第二调用模块62,用于若第二判断模块61判断结果为是,则调用eval函数对所述脚本进行动态解释;

[0093]第二加载模块63,用于若第二判断模块61判断结果为否,则为所述脚本创建脚本标签,将src属性设置为data类型,传入base64算法编码后的脚本,对编码后的脚本进行动态加载。

[0094]综上所述,本发明提供的浏览器脚本的缓存方法及系统,在浏览器加载页面时,以Ajax的方式请求获取脚本内容,且每次浏览器使用Ajax的请求之前先判定本地存储中是否存在对应脚本,如果存在,则直接从本地存储获取,不再发送Ajax的请求获取,实现对浏览器缓存更好的控制,减少不必要的脚本加载,提高网页加载速度。

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention provides a browser script caching method and system. The method comprises the steps that a browser obtains scripts according to an Ajax request; if the scripts are executed one by one in a dynamic explanation mode according to an Ajax request sequence; the successfully-executed scripts are stored into a local storage; unsuccessfully-executed scripts are encoded and then stored into the local storage. The request scripts of the Ajax method are adopted, the obtained scripts are dynamically executed, the scripts are cached into the local storage if executed successfully, and the scripts are encoded and then cached locally if executed unsuccessfully; compared with the prior art for adopting a label for marking a script needing to be loaded, according to the scheme, the scripts are cached into the local storage, the corresponding scripts can be obtained locally directly during a next request instead of obtaining all the scripts again, browser caching is better controlled, unnecessary script loading is reduced, and the webpage loading speed is increased.

Description

technical field [0001] The invention relates to the field of computer technology, in particular to a browser script caching method and system. Background technique [0002] At present, browser script caching has different implementation methods according to different browsers. Usually, script tags are used to mark the scripts to be loaded, and the browser loads the scripts according to the script addresses in the tags. [0003] For example, the Chinese patent with the publication number CN 104407979 A provides a script detection method, including: loading the original website; monitoring whether a jump event occurs on a webpage in the original website; When the jump event occurs on the page, block the jump of the web page in the original website; intercept the page jump request of the web page in the original website, and read the required page from the page jump request The link address of the webpage where the jump occurs; the target webpage is obtained through the link a...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F17/30G06F9/455
CPCG06F9/45529G06F9/45508G06F9/45516G06F16/9574G06F16/986
Inventor 刘德建陈丛亮郭玉湖
Owner FUJIAN TQ DIGITAL
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products