高性能网站建设指南——记录<减少HTTP请求>

1、减少HTTP请求

1.1、图片地图

允许一个图片关联多个URL,目标URL取决于用户在图片上的点击位置。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p>点击太阳或其他行星,注意变化:</p>

<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">

<map name="planetmap">
  <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
  <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
  <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>

</body>
</html>

效果:点击不同星球跳转 

1.2、CSS Sprites

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        i {
            width: 30px;
            height: 24px;
            float: left;
            background: url(images/sprite.png);
            margin: 5px 10px 0 0;
        }

        .cat1 i {
            background-position: 0 0;
        }

        .cat2 i {
            background-position: 0 -24px;
        }

        .cat3 i {
            background-position: 0 -48px;
        }

        .cat4 i {
            background-position: 0 -72px;
        }
    </style>
</head>

<body>
    <li class="cat1"><i></i>
        <h3>服饰内衣</h3>
    </li>
    <li class="cat2"><i></i>
        <h3>鞋包配饰</h3>
    </li>
    <li class="cat3"><i></i>
        <h3>运动户外</h3>
    </li>
    <li class="cat4"><i></i>
        <h3>珠宝手表</h3>
    </li>
</body>

</html>

效果:拿到指定图标 

1.3、内联图片

通过data:URL模式可以在Web页面中包含图片但无序任何HTTP请求。

data:URL是内联在页面中,在跨越不同页面时不会被缓存。最好的方法是将内联图片作为背景。将该CSS规则方在外部样式表中。意味着数据可以缓存在样式表内。

1.4、合并脚本和样式表

模块化将代码分到许多小文件中会降低性能,因为每个文件都会导致一个额外的HTTP请求。

由于每个页面所需的脚本不同,会有多脚本组合的情况,所以权衡组合是否是可管理模式十分重要。

首页访问页面时的响应事件决定这用户是否放弃你的网站还是不停的进行回访。

高性能网站建设指南目录→高性能网站建设指南——记录<首页>_SONG宋人头的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
修改以下代码实现四列在同一排上<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>底部设计</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <style> footer { background-color: #f5f5f5; padding: 50px 0;} footer h4 { font-size: 18px; font-weight: bold;} footer p { font-size: 14px; line-height: 1.5;} footer ul { list-style: none; padding: 0; margin: 0;} footer ul li { margin-bottom: 10px;} footer ul li a { color: #333; font-size: 14px; line-height: 1.5; text-decoration: none;} footer ul li a:hover { text-decoration: underline;} </style> </head> <body> <footer> <div class="container"> <div class="row"> <div class="col-md-3 col-sm-6"> <h4>关于我们</h4> <p>我们是一家专业的电商公司,致力于为客户提供高品质的商品和服务。</p> </div> <div class="col-md-3 col-sm-6"> <h4>联系我们</h4> <p>电话:123-456-7890</p> <p>邮箱:info@ecommerce.com</p> </div> <div class="col-md-3 col-sm-6"> <h4>购物指南</h4> <ul> <li><a href="#">购物流程</a></li> <li><a href="#">注册登录</a></li> <li><a href="#">会员中心</a></li> <li><a href="#">支付方式</a></li> </ul> </div> <div class="col-md-3 col-sm-6"> <h4>合作伙伴</h4> <ul> <li><a href="#">京东</a></li> <li><a href="#">淘宝</a></li> <li><a href="#">天猫</a></li> <li><a href="#">苏宁</a></li> </ul> </div> </div> </div> </footer> </body> </html>变成一行四列
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值