InstantClick.js插件,让网页提前预加载,网站无刷新跳转页面

InstantClick,让网站的访问速度获得更大的提升,这是一个js插件,只需要简单配置到你的网站,即可实现网站页面的预加载。

演示

image

上面是我的演示,当点击a标签的时候,跳转到一个页面,我们可以看到,浏览器是没有刷新页面的,而是直接更改了浏览器url,全程没有刷新的动作,但是内容已经是另一个页面了。

这里提供我的网站给大家操作查看一下演示:https://www.likeyun.cn/pc/

代码

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
    <title>无刷新预加载页面</title>
    <script class="lazy" data-src="instantclick.min.js"></script>
    <style type="text/css">
        #instantclick-bar {
          display: none;
        }
    </style>
</head>
<body>
<div>
    <h2><a href="page.php?url=baidu">百度一下,你就知道</a></h2>
    <h2><a href="page.php?url=taobao">淘宝,让天下没有难做的生意</a></h2>
    <h2><a href="page.php?url=qq">腾讯游戏,毁我青春</a></h2>
</div>
<script data-no-instant>InstantClick.init();</script>
</body>
</html>

page.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body style="margin:0;">
    <?php
        header("Content-type:text/html;charset=utf-8");
        if ($_GET["url"] == 'baidu') {
            echo "<title>百度</title>";
            // echo "<h1>你好,我是李彦宏</h1>";
            echo "<iframe src='http://www.baidu.com' style='width:100%;height:100%;position:fixed;' frameborder='0'></iframe>";
        }else if ($_GET["url"] == 'taobao') {
            echo "<title>淘宝</title>";
            // echo "<h1>你好,我是马云</h1>";
            echo "<iframe src='http://www.taobao.com' style='width:100%;height:100%;position:fixed;' frameborder='0'></iframe>";
        }else if ($_GET["url"] == 'qq') {
            echo "<title>腾讯</title>";
            // echo "<h1>你好,我是马化腾</h1>";
            echo "<iframe src='http://www.qq.com' style='width:100%;height:100%;position:fixed;' frameborder='0'></iframe>";
        }else{
            echo "<h1>别乱来...</h1>";
        }
    ?>
</body>
</html>

如何使用

其实很简单的,只需要将插件的js引入页面,然后初始化即可,下面是我们要引入的文件。

<script src="instantclick.min.js"></script>

然后,在网站</body>标签之前加入这句

<script data-no-instant>InstantClick.init();</script>

这样,你的网站也能快速接入无刷新的感觉的预加载技术!

官网

直接去官网下载生产版本的js插件吧!
link:http://instantclick.io/

本文作者

Author:TANKING
Date:2021-01-13
Wechat:sansure2016
Web:http://www.likeyun.cn/
Qrcode:Join in

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TANKING-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值