Atitit.减少http请求数方案

1. 原理与方法1

1.1. -------jsp1

1.2. "index/js.txt";2

1.3. connReduceDync2

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请求数方案的更多相关文章

  1. 页面优化——减少HTTP请求数

    1.关于减少http请求数 关于减少http请求数,是前端开发性能优化的一个非常重要方面,所以在基本所有的优化原则里,都有这一条原则:减少http请求数. 先不考虑其他的,我们先考虑为什么减少http ...

  2. web性能优化--减少客户端请求数(一)

    多图标合并,用css分隔 设置较长时间的过期时间 合并多个css文件 合并多个js文件 根据域名划分内容 首先介绍一款速度测试工具:webpagetest(填上url,username,passwor ...

  3. 高性能WEB开发 为什么要减少请求数,如何减少请求数!

    http请求头的数据量 [声明] 转载  原文出处:http://www.blogjava.net/BearRui/. 谢谢我们先分析下请求头,看看每次请求都带了那些额外的数据.下面是监控的googl ...

  4. 减少HTTP请求之将图片转成二进制并生成Base64编码,可以在网页中通过url查看图片(大型网站优化技术)

    在网站开发过程中,对于页面的加载效率一般都想尽办法求快.那么,怎么让才能更快呢?减少页面请求 是一个优化页面加载速度很好的方法.上一篇博文我们讲解了 “利用将小图标合成一张背景图来减少HTTP请求”, ...

  5. 减少HTTP请求之合并图片详解(大型网站优化技术)

    原文:减少HTTP请求之合并图片详解(大型网站优化技术) 一.相关知识讲解 看过雅虎的前端优化35条建议,都知道优化前端是有多么重要.页面的加载速度直接影响到用户的体验.80%的终端用户响应时间都花在 ...

  6. 高并发大流量专题---3、前端优化(减少HTTP请求次数)

    高并发大流量专题---3.前端优化(减少HTTP请求次数) 一.总结 一句话总结: 图片地图:使用<map><area></area></map>标签. ...

  7. 减少图片HTTP 请求的方案

    <Higb Performance Web Sites>(中文名:“高性能网站建设指南”)这本书对于前端工程师来说,绝对值得一读.本人有幸从公司借阅了,但不幸的是感觉翻译有点怪怪的.尤其是 ...

  8. 前端性能优化 —— 减少HTTP请求

    简要:对于影响页面呈选 的因素有3个地方:服务器连接数据库并计算返回数据 , http请求以及数据(文件)经过网络传输 , 文件在浏览器中计算渲染呈选: 其中大约80%的时间都耗在了http请求上,所 ...

  9. 使用CSS sprites减少HTTP请求

    sprites是鬼怪,小妖精,调皮鬼的意思,初听这个高端洋气的名字我被震慑住了,一步步掀开其面纱后发觉很简单的东西,作用却很大 神马是CSS 小妖精 CSS sprites是指把网页中很多小图片(很多 ...

随机推荐

  1. SQL Server--CheckPoint

    http://www.cnblogs.com/TeyGao/category/526201.html

  2. Linux 内核中的 GCC 特性

    https://www.ibm.com/developerworks/cn/linux/l-gcc-hacks/ GCC 和 Linux 是出色的组合.尽管它们是独立的软件,但是 Linux 完全依靠 ...

  3. winform listview默认第一项光标选中

    if (this.lsvSortingHeadList.Items.Count > 0) { this.lsvSortingHeadList.Focus(); this.lsvSortingHe ...

  4. VB里的TEXT控件只能输入数字的代码

    " '先声明一个常量,并把你想禁用或允许输入的内容赋值给它 Private Sub Text1_KeyPress(KeyAscii As Integer) '只能输入数字 KeyAscii ...

  5. fmri 实验设计 / 范式设计/ paradigm design

    reference:http://www.psychology.gatech.edu/cabi/Resources/Course/index.html sluggish 懒散的,无精打采的.哈哈,pp ...

  6. [java] 模拟QPS

    在WEB服务器端,每日的访问量巨大.在非生产环境需要对服务器进行压力测试,一般使用后台线程和Sleep方式来模拟线上的压力.这里使用ScheduledExecutorService实现一种简单的QPS ...

  7. Linux 设备驱动--- 并发 与 竞态 --- atomic_t --- atomic_dec_and_test --- 原子操作

    并发: 多个执行单元同时被执行. 竞态: 并发的执行单元对资源 ( 硬件资源和软件上的全局变量等 ) 的访问导致的竞争状态. 并发的处理: 处理并发的常用技术是加锁或者互斥,即保证在任何时间只有一个执 ...

  8. 一些数据 bandwidth之类

    33ms  2436x1125 full resolution write bandwidth  300MB/s memory bandwidth snapdragon 630 10GB/3   // ...

  9. GDALDataset的创建和销毁

    之前在GDALDestroyDriverManager 分析中没有看到对dGDALDatasert的回收.先看一个例子程序,这个例子打开了一个tif文件,读取了一些基本信息. 为了简单示范,没有写成C ...

  10. C# 继承实现父类方法、重写、重载

    继承是派生类(子类)去实现(重写<override>.重构<new>)基类(父类)的方法或属性.从而获取在派生类中要实现的功能. 子类调用父类构造方法,在父类中有个实现姓名和年 ...