Atitit.减少http请求数方案
Atitit.减少http请求数方案
1. 原理与方法
界面调用js.jsp css.js, 如果存在缓存文件就返回缓存文件,否则
读取js css列表文件
读取文件,拼接成一个大的js css文件,然后缓存起来
作者:: ★(attilax)>>> 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙, EMAIL:1466519819@qq.com
转载请注明来源: 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.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
//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.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
//System.out.println(c.readCacheOrjoinNout());//product 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()+"/"+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("/"))
f=f.substring(1);
String full_file=dir+"/"+f;
li.add(full_file);
}
}
return li;
}
}
----------finis
Atitit.减少http请求数方案的更多相关文章
- 页面优化——减少HTTP请求数
1.关于减少http请求数 关于减少http请求数,是前端开发性能优化的一个非常重要方面,所以在基本所有的优化原则里,都有这一条原则:减少http请求数. 先不考虑其他的,我们先考虑为什么减少http ...
- web性能优化--减少客户端请求数(一)
多图标合并,用css分隔 设置较长时间的过期时间 合并多个css文件 合并多个js文件 根据域名划分内容 首先介绍一款速度测试工具:webpagetest(填上url,username,passwor ...
- 高性能WEB开发 为什么要减少请求数,如何减少请求数!
http请求头的数据量 [声明] 转载 原文出处:http://www.blogjava.net/BearRui/. 谢谢我们先分析下请求头,看看每次请求都带了那些额外的数据.下面是监控的googl ...
- 减少HTTP请求之将图片转成二进制并生成Base64编码,可以在网页中通过url查看图片(大型网站优化技术)
在网站开发过程中,对于页面的加载效率一般都想尽办法求快.那么,怎么让才能更快呢?减少页面请求 是一个优化页面加载速度很好的方法.上一篇博文我们讲解了 “利用将小图标合成一张背景图来减少HTTP请求”, ...
- 减少HTTP请求之合并图片详解(大型网站优化技术)
原文:减少HTTP请求之合并图片详解(大型网站优化技术) 一.相关知识讲解 看过雅虎的前端优化35条建议,都知道优化前端是有多么重要.页面的加载速度直接影响到用户的体验.80%的终端用户响应时间都花在 ...
- 高并发大流量专题---3、前端优化(减少HTTP请求次数)
高并发大流量专题---3.前端优化(减少HTTP请求次数) 一.总结 一句话总结: 图片地图:使用<map><area></area></map>标签. ...
- 减少图片HTTP 请求的方案
<Higb Performance Web Sites>(中文名:“高性能网站建设指南”)这本书对于前端工程师来说,绝对值得一读.本人有幸从公司借阅了,但不幸的是感觉翻译有点怪怪的.尤其是 ...
- 前端性能优化 —— 减少HTTP请求
简要:对于影响页面呈选 的因素有3个地方:服务器连接数据库并计算返回数据 , http请求以及数据(文件)经过网络传输 , 文件在浏览器中计算渲染呈选: 其中大约80%的时间都耗在了http请求上,所 ...
- 使用CSS sprites减少HTTP请求
sprites是鬼怪,小妖精,调皮鬼的意思,初听这个高端洋气的名字我被震慑住了,一步步掀开其面纱后发觉很简单的东西,作用却很大 神马是CSS 小妖精 CSS sprites是指把网页中很多小图片(很多 ...
随机推荐
- php概率算法
这是一个很经典的概率算法函数: function get_rand($proArr) { $result = ''; //概率数组的总概率精度 $proSum = array_sum($proArr) ...
- ISP图像调试工程师——自动曝光(熟悉3A算法)
基于图像的自动曝光算法研究 : https://wenku.baidu.com/view/c854fa93fd0a79563c1e72ba.html
- Dr.memory
Run Dr.memory on visual c++ 2013 Title: Dr. Memory Command: C:\Program Files (x86)\Dr. Memory\bin\dr ...
- jersey rest webservice
参考官网:https://jersey.github.io/documentation/latest/getting-started.html#new-webapp 创建一个 JavaEE Web A ...
- 【笔记】git 的常用操作命令(持续更新。。。)
项目正在如火如荼的开展,代码量的繁多不得不令我们运用 git 这个有用的工具去管理我们共同协作的代码 git 在这里不作什么介绍了,百度一大堆的教程 首推廖雪峰老师的:http://www.liaox ...
- MySQL建表设置外键提示错误
错误内容: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to ...
- iOS 使用NSUserdefault 保存自定义的 对象
一:NSUserDefaults支持的数据格式有:NSNumber(Integer.Float.Double),NSString,NSData,NSArray,NSDictionary,BOOL类型: ...
- Android Studio修改项目名和包名
为了提高开发效率,有时候需要使用现有的一些开源项目,记录一下自己修改项目名和包名的方法. 1.首先,修改包名(清单文件里找), ①展开所有包 ②选中想要修改的包,shift+F6(也可右键Refact ...
- java阅读笔记
前言:面向对象设计的几大原则? 1>针对接口编程,而不是针对实现编程 2>优先使用对象组合,而不是类继承 1.只根据抽象类中定义的接口来操纵对象有以下两个好处? 1)客户无须知道他们使用对 ...
- java写的小脚本,用来受mDNS消息
太ugly了,但是可以工作,抓了包下来,用前面DNS message structure做了下比较. 代码如下: import java.net.DatagramPacket; import java ...