Atitit. reduces the number of http requests and atitit requests

Source: Internet
Author: User

Atitit. reduces the number of http requests and atitit requests

Atitit. scheme to reduce the number of http requests

 

 

1. Principles and Methods 1

1.1. ------- jsp1

1.2. "index/js.txt"; 2

1.3. conn1_cedync2

 

1. Principles and Methods

The interface calls js. jsp css. js. If a cached file exists, the cached file is returned. Otherwise

Read js css List Files

Read files, splice them into a large js css file, and cache them.

 

Author ::★(Attilax)> nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui) Chinese name: AI long, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://www.cnblogs.com/attilax/

 

1.1. ------- Jsp

 

<% @ Page language = "java" import = "java. util. *, com. csmy. my. center. util. CTUtils" pageEncoding = "UTF-8" %>

 

<% @ Page import = "com. attilax. util. conn1_cedync" %>

<% @ Page import = "com. attilax. io. pathx" %>

 

 

<%

 

Conn1_cedync c = new conn1_cedync ();

// C. res = "com. attilax, core/import. js, core/core. js, core/yaml. js | com. atilax. frmwk,/jquery-1.8.3.min.js ";

C. resfile = "index/js.txt ";

C. resfileUse = true;

// C. base = "" // def is approot

C. output = "index/jobus_index.js"; // index/jobus. js

 

C. recreateMode = true; // else use append mode

// System. out. println (c. joinNout (); // trest mode

// System. out. println ();/

 

// Return;

%>

<% = C. readCacheOrjoinNout () %>

 

1.2. "Index/js.txt ";

 

Index/img. js

Com. atilax. frmwk/jquery-1.8.3.min.js

Com. attilax/HRE. js

Com. attilax/jsbridge/jsb_v8q414.js

Com. attilax/templete/jquery. tmpl. js

Com. atilax. frmwk/unslider. min. js

Com. attilax/core/coreV3.js

CmsPhone4jobusImp/list. js

Com. attilax/log/logV2.js

1.3. ConnReduceDync

Package com. attilax. util;

 

Import java. io. File;

Import java. util. List;

Import java. util. Map;

 

Import com. attilax. coll. ListX;

Import com. attilax. collection. listUtil;

Import com. attilax. io. filex;

Import com. attilax. io. pathx;

Import com. google. common. collect. Lists;

Import com. google. common. collect. Maps;

 

/**

* Servlet

* @ Author Administrator

*

* Com. attilax. util. conn1_cedync

*

*/

Public class connReduceDync extends ConnReducerV2 {

 

 

Public String resfile;

Public boolean resfileUse = false;

 

 

Public static void main (String [] args ){

Conn1_cedync c = new conn1_cedync ();

C. res = "com. attilax, core/import. js, core/core. js, core/yaml. js | com. atilax. frmwk,/jquery-1.8.3.min.js ";

C. resfile = "list/list_jss.txt ";

C. resfileUse = true;

// C. base = pathx. webAppPath ();

C. output = "list/jobus_list.js"; // index/jobus. js

// C. output_css = c. base + "/list/jobus_list.css ";

// C. isGeneCss = false;

C. recreateMode = true; // else use append mode

C. genefile = true;

System. out. println (c. joinNout (); // trest mode

// System. out. println (c. readCacheOrjoinNout (); // product mode

// Map m = Maps. newjavashashmap ();

// M. put ("res", s );

System. out. println ("-- f ");

 

}

 

Public String readCacheOrjoinNout (){

Output = pathx. fillFullpath (output );

If (new File (this. output). exists ())

Return filex. read (this. output );

Return joinNout ();

}

 

Public String joinNout (){

Output = pathx. fillFullpath (output );

Gene ();

Return this. resCache;

}

 

Private void gene (){

Resfile = pathx. webAppPath () + "/" + resfile;

List <String> li = Lists. newcategory List ();

If (resfileUse = false)

Li = parseLi (base );

If (resfileUse)

Li = listUtil. trimLine (filex. read2list (this. resfile ));

For (String line: li ){

Line = line. trim ();

If (line. length () = 0)

Continue;

Importx (line );

 

}

Reduce ();

}

 

Private List <String> parseLi (String base ){

List <String> li = Lists. newArrayList ();

String reses = res;

String [] rows = reses. split ("\\| ");

For (String row: rows ){

String [] cols = CsvUtil. toCols (row );

String dir = cols [0];

 

For (int I = 1; I <cols. length; I ++ ){

 

 

String f = cols [I]. trim ();

If (f. trim (). startsWith ("/"))

F = f. substring (1 );

String full_file = dir + "/" + f;

Li. add (full_file );

}

}

Return li;

}

 

}

---------- Finis

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.