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是指把网页中很多小图片(很多 ...
随机推荐
- 面试DB优化
高频全表扫描 0.5 表大小超过200M,且SQL高频执行(15分钟内超过500次),PIR 3级,表大小超过高速缓存的1.5%,报PIR 2级. 禁止使用select * 0.5 禁止使用selec ...
- Spark学习视频整合
1.<Scala深入浅出实战经典>http://pan.baidu.com/s/1pJnAUr5 2.<Spark纯实战公益大讲坛>http://pan.baidu.com/s ...
- http://blog.sina.com.cn/s/blog_546abd9f0101c6au.html
http://blog.sina.com.cn/s/blog_546abd9f0101c6au.html
- [转载]抓包工具Charles乱码解决办法
FROM: http://blog.csdn.net/huanghanqian/article/details/52973651 安装 SSL 证书 Mac 端 首先去 http://www.char ...
- java匿名内部类之RocketMQ中的应用
匿名内部类在spring中没怎么见用,在RocketMQ中有大量的应用. 确实可以提高开发效率.这可能代表两种写代码的态度吧. 匿名内部类简单来说就是直接在函数中实现接口方法,不需要声明一个接口实现类 ...
- [Angular] Improve Server Communication in Ngrx Effects with NX Data Persistence in Angular
Communicating with a remote server via HTTP presents an extra level of complexity as there is an inc ...
- Solidworks如何等比例缩小放大模型
比如初始化的模型,笔记本长度只有120mm,实际上应该是3倍左右 右击特征,勾选模具工具,然后可以发现多出来一个页面 点击比例缩放,选中要缩放的特征,设置比例,然后打钩 可以发现已经缩放到 ...
- 有些类库(node.js版)
做项目经常会用到好些类库,大的还好说,用的多了自然记住了名字.如express. 但也有些小而精湛的类库,不仅提供了良好的功能,本身的实现也值得研究.暂记于此. 1.web类 request 简 ...
- eslint for...in 报错处理
示例代码: <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...
- [Objective-C A]-知识点锦集
1.@autoreleasepool why1 2.retain O-C内存管理和点语法 1>OC内存管理正常情况要使用大量的retain和relrese操作 2>点语法可以减少使用re ...