一行JS代码实现页面图片延迟加载[jquery lazyload]

    提高页面加载速度的方法有很多种,这里推荐一种在页面图片较多的时,提高页面整体加载速度的方法–延迟加载(lazyload)。

    当一个页面图片较多时,页面整体的数据就会比较大,一次load完再展示,页面打开会显得比较慢,延迟加载就是在浏览器在解析HTML时不对图片进行加载,当页面打开后,监控滚动条对本屏图片进行逐个载入,这样可以将一个页面数据请求分散为多个,大大减少一次请求load数据的时间,从而提高页面的加载速度。
    借助 jquery lazyload插件可以轻松实现延迟加载,调用方式如下:
    引入jquery和jquery lazyload插件: 

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.lazyload.js" type="text/javascript"></script>

图片标签处理:

<img data-original="img/example.jpg" width="640" height="480">
<!--
<img data-original="图片路径" width="640" height="480">
即把img标签src属性改为data-original
-->
    在页面加载完成后调用: 

<script>
 $(function() {
  $("img").lazyload();
  //加上淡出效果
  //$("img").lazyload({ effect : "fadeIn" });
 });
</script>
    下载地址:下载 
     转载请注明出处:怡然之乐 – FineYi

一个朋友的留言–@老白

昔我往矣 一路楊柳怡怡
今我來思 一路風雪漫漫
那歡笑 那憂傷 不自忘亦難忘 已侵蝕成生命的斑斑銹跡
春红謝了几秋 素魄娟娟几载
小院梨花芳菲依然
风雨不改其白
何以桃花雨里迷离
怡然不悔其艳
梧桐枝上栖燕雀
志在觅食终究挥翅草间
招凰方永 地久天长
风来了 张双臂尽情畅享
风去了 挥衣袖决不彷徨
悠悠竹筏载不动的伤啊
结成痂悄悄收藏
泪化珍珠
珠照回首的迷惘
璀璨目顾的远方
 
                   –@老白

CentOS6.4下coreseek 4.1(sphinx)安装配置手记 完美支持MySQL数据源

CentOS6.4下coreseek 4.1(sphinx)安装配置手记 完美支持MySQL数据源
系统环境:
OS:                 CentOS6.4 64位
MySQL:          5.1.63
coreseek:        4.1
安装、配置过程如下:
#当前路径
[root@E sphinx]# pwd
/home/sphinx
#安装依赖包
[root@E sphinx]# yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
#下载coreseek4.1
[root@E sphinx]# wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
#解压缩
[root@E sphinx]# tar zxvf coreseek-4.1-beta.tar.gz
#安装mmseg
[root@E sphinx]# cd coreseek-4.1-beta/mmseg-3.2.14/
[root@E mmseg-3.2.14]# ./bootstrap #输出的warning信息可以忽略,如果出现error则需要解决
[root@E mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg3
[root@E mmseg-3.2.14]# make && make install
[root@E mmseg-3.2.14]# cd ..

##安装coreseek
[root@E coreseek-4.1-beta]# cd csft-4.1/
[root@E csft-4.1]# sh buildconf.sh #输出的warning信息可以忽略,如果出现error则需要解决
[root@E csft-4.1]# ./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql

[root@E csft-4.1]# make && make install
[root@E csft-4.1]# cd ..

#测试mmseg分词,coreseek搜索(需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文)
[root@E coreseek-4.1-beta]# cd testpack/
[root@E testpack]# cat var/test/test.xml #此时应该正确显示中文
#mmseg程序 -d 词库目录 指定数据源
[root@E testpack]# /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
#创建索引
[root@E testpack]# /usr/local/coreseek/bin/indexer -c etc/csft.conf --all
#执行搜索测试
[root@E testpack]# /usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索
#测试成功
Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
 using config file 'etc/csft.conf'...
index 'xml': query '网络搜索 ': returned 1 matches of 1 total in 0.000 sec
displaying matches:
1. document=1, weight=1590, published=Thu Apr 1 22:20:07 2010, author_id=1
words:
1. '网络': 1 documents, 1 hits
2. '搜索': 2 documents, 5 hits
#为了使sphinx直接支持mysql数据源 需要对coreseek重新编译安装
#重新编译安装后的coreseek可以支持mysql和xml数据源
[root@E testpack]# cd ..
[root@E coreseek-4.1-beta]# pwd
/home/sphinx/coreseek-4.1-beta
[root@E coreseek-4.1-beta]# cd csft-4.1/$ make clean
[root@E coreseek-4.1-beta]#./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql
###配置、测试mysql数据源###
导入测试数据 sql点击下载
#安装mysql依赖包
yum install mysql mysql-server php-mysql -y
#修改配置配置文件
[root@E testpack]# cd ../testpack/
[root@E testpack]# vi etc/csft_mysql.conf
#只需要修改 源定义 中的数据库的相关配置(数据库地址、用户名、密码、库名) 其它配置不需修改 如下所示:
#源定义
source mysql
{
    type = mysql
    sql_host = localhost #数据库主机地址
    sql_user = root #数据库用户名
    sql_pass = 111111 #数据库密码
    sql_db = sphinx #数据库库名
    sql_port = 3306
    sql_query_pre = SET NAMES utf8
    sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
                                                              #sql_query第一列id需为整数
                                                              #title、content作为字符串/文本字段,被全文索引
    sql_attr_uint = group_id #从SQL读取到的值必须为整数
    sql_attr_timestamp = date_added #从SQL读取到的值必须为整数,作为时间属性
    sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的
字符集
    sql_query_info = SELECT * FROM documents WHERE id=$id #命令行查询时,从数据库读取原始数据信息
}

 

#创建mysql数据源索引
[root@E testpack]# pwd
/home/sphinx/coreseek-4.1-beta/testpack
#索引器 -c 配置文件 --all
[root@E testpack]# /usr/local/coreseek/bin/indexer -c etc/csft_mysql.conf --all
Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
 using config file 'etc/csft_mysql.conf'...
indexing index 'mysql'...
ERROR: index 'mysql': sql_connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) (DSN=mysql://root:***@localhost:3306/sphinx).
total 0 docs, 0 bytes
total 0.000 sec, 0 bytes/sec, 0.00 docs/sec
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
#上面有报错 创建索引失败
#找到mysql.sock的路径(可以去mysql的配置文件/etc/my.cnf中查看 本机在/tmp/mysql.sock)
#建立软连接
[root@E testpack]# mkdir /var/lib/mysql
[root@E testpack]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
#创建mysql数据源索引成功
[root@E testpack]# /usr/local/coreseek/bin/indexer -c etc/csft_mysql.conf --all
Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
 using config file 'etc/csft_mysql.conf'...
indexing index 'mysql'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 7545 bytes
total 0.016 sec, 467269 bytes/sec, 185.79 docs/sec
total 3 reads, 0.000 sec, 2.8 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 2.2 kb/call avg, 0.0 msec/call avg

#测试mysql数据源 搜索
[root@E testpack]# /usr/local/coreseek/bin/search -c etc/csft_mysql.conf 网络搜索
Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)
 using config file 'etc/csft_mysql.conf'...
index 'mysql': query '网络搜索 ': returned 1 matches of 1 total in 0.000 sec
displaying matches:
1. document=1, weight=1590, group_id=2, date_added=Thu Apr 1 22:20:07 2010
        id=1
        title=愚人节最佳蛊惑爆料 谷歌300亿美元收购百度
        content=据国外媒体报道,谷歌将巨资收购百度,......<正文省略很多字>......李彦宏也承认当前百度在日本还处于初级发展阶段,但他也预言“2012年,百度与Google划洋而治”,对此我们拭目以待!
        date_added=2010-04-01 22:20:07
        author_id=1
        group_id=2
words:
1. '网络': 1 documents, 1 hits
2. '搜索': 2 documents, 5 hits
coreseek词库扩展请参考:sphinx(coreseek)导入搜狗词库
稍后完善 实时索引的创建及维护

转载请注明出处:怡然之乐 – FineYi

参考资料:coreseek and coreseek