HTML5技术

Atitit.减少http请求数方案 - attilaxAti

字号+ 作者:H5之家 来源:博客园 2016-05-17 17:00 我要评论( )

1. 原理与方法 界面调用 js.jsp css.js , 如果存在缓存文件就返回缓存文件,否则 读取 js css 列表文件 读取文件,拼接成一个大的 js css 文件,然后缓存起来 EMAIL:1466519819@qq.com 转载请注明来源: 1.1. -------jsp %@ page language="java" import="j

 

 

 

1. 原理与方法

界面调用js.jsp  css.js, 如果存在缓存文件就返回缓存文件,否则

读取js css列表文件

读取文件,拼接成一个大的js css文件,然后缓存起来

 

  EMAIL:1466519819@qq.com

转载请注明来源: 

 

1.1. -------jsp

 

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

 

<%@ page import="com.attilax.util.connReduceDync"%>

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

 

 

<%

 

connReduceDync c=new connReduceDync();

//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

 

// 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.connReduceDync

 *

 */

public class connReduceDync extends ConnReducerV2 {

 

 

public String resfile;

public boolean resfileUse=false;

 

 

public static void main(String[] args) {

connReduceDync c=new connReduceDync();

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

//Map m=Maps.newLinkedHashMap();

//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()+"http://www.cnblogs.com/"+resfile;

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

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("http://www.cnblogs.com/"))

f=f.substring(1);

String full_file=dir+"http://www.cnblogs.com/"+f;

li.add(full_file);

}

}

return li;

}

 

}

 ----------finis

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTTP协议学习随笔 - 糖醋酸辣椒

    HTTP协议学习随笔 - 糖醋酸辣椒

    2017-05-01 18:03

  • HTTP认证 - 妙音天女

    HTTP认证 - 妙音天女

    2017-03-27 17:00

  • HTTP状态码 - 妙音天女

    HTTP状态码 - 妙音天女

    2017-03-25 13:01

  • SuperWebClient -一个基于CURL的.NET HTTP/HTTPS模拟神组件(1) - ByteWorke

    SuperWebClient -一个基于CURL的.NET HTTP/HTTPS模拟神组件(1) - B

    2017-02-28 12:01

网友点评