前言:第一次用移动网页加速器,感觉好心情都被弄坏了。确实性能提高了不少,但是限制js,对于一些交互实现都成问题。MIP是Mobile Instant Pages的缩写,指百度移动网页加速器, 是一套应用于移动网页的开放性技术标准。通过提供MIP-HTML规范、MIP-JS运行环境以及MIP-Cache页面缓存系统,实现移动网页加速。

1. 写一个mip页面,第一步创建 HTML 文件

创建一个标准的 HTML 文件,注意事项:

  • 在 <html> 标签中增加 mip 属性标识。
  • 编码为 utf-8 。
  • 添加 meta-viewport,用于移动端展现。我们第一例子都是从Hello World开始
<!DOCTYPE html>
<html mip>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

2. 想要使用MIP,必须配置它的运行环境

在 HTML 代码前后分别添加 MIP依赖的 mip.css 和 mip.js 。

<!DOCTYPE html>
<html mip>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"><!-希望大家注意一下这里,推荐使用1,不要写成1.0-->
<link rel="stylesheet" type="text/css" href="https://c.mipcdn.com/static/v1/mip.css">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
<script src="https://c.mipcdn.com/static/v1/mip.js"></script>
</body>
</html>

3. 添加 MIP 内置一些标签

标签 使用范围 备注
<img> 禁止使用 需替换为 <mip-img>
<video> 禁止使用 需替换为 <mip-video>
<audio> 禁止使用 需替换为 <mip-audio>
<iframe> 禁止使用 需替换为 <mip-iframe>
<form> 禁止使用 需替换为 <mip-form>
<frame> 禁止使用  
<frameset> 禁止使用  
<object> 禁止使用  
<param> 禁止使用  
<applet> 禁止使用  
<embed> 禁止使用  
<script> 限制使用 禁止使用 <script> 不包括以下两种场景:

  • src 属性存在

    • type 必须 text/javascript 、application/javascript 或 type 不存在(即没有 type 属性)
    • src 必须是 https 或 // 开头
    • src 必须是 MIP 域名,否则禁止使用
    • 如果在 <head> 中,必须加 async 属性
  • src 属性不存在script 父节点不能是 template
    • type 必须是 application/json 或 application/ld+json
    • script 不强制大小写,不区分单双引号
<style> 替换为 <style mip-custom> 只能在 <head> 标签中使用一次

ps:1注意出于速度考虑,建议內联使用 CSS 样式。所有样式写在 <style mip-custom></style> 中,注意:style 标签仅允许出现一次

  2替换禁用标签

一个完整的例子

<!DOCTYPE html>
<html mip>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="stylesheet" type="text/css" href="https://c.mipcdn.com/static/v1/mip.css">
<!--TODO: canonical href需要替换成原页面url-->
<link rel="canonical" href="https://www.example.com/your/path.html">
<title>MIP页Demo效果</title>
<!--TODO: 替换样式-->
<style mip-custom>
body { margin: 10px;}
.red-text { color: #f00;}
.middle-text { text-align: center; font-size: 20px;}
hr { margin: 20px 0;}
a { border: 1px solid #ddd; padding: 10px; display: block;}
</style>
<!-- noscript 标签是为了在不支持 script 的环境下快速的展现 MIP 页面,推荐使用 -->
<noscript>
<style mip-officialrelease>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style>
</noscript>
</head>
<body>
<!--自定义样式-->
<p class="middle-text">增加样式</p>
<p class="red-text">MIP页支持修改css样式</p>
<hr> <!--跳转链接, 落地页同为MIP-->
<p class="middle-text">mip 跳转链接</p>
<a data-type="mip" data-title="目标页面标题" href="https://www.mipengine.org/doc/00-mip-101.html">跳转到MIP新手指南 (MIP)</a>
<!--跳转链接, 落地页不是MIP-->
<a target="_blank" href="https://github.com/mipengine">跳转到GitHub (非MIP)</a>
<hr> <!--图片组件-->
<p class="middle-text">mip-img 图片组件</p>
<mip-img layout="fixed" width="200" height="130" src="https://www.mipengine.org/static/img/mip_logo_3b722d7.png" alt="MIP LOGO"></mip-img>
<hr>
<mip-carousel autoplay defer="3500" layout="responsive" width="600" height="400" indicator>
<mip-img src="https://www.mipengine.org/static/img/sample_01.jpg">
</mip-img>
<mip-img src="https://www.mipengine.org/static/img/sample_02.jpg">
</mip-img>
<mip-img src="https://www.mipengine.org/static/img/sample_03.jpg">
</mip-img>
</mip-carousel>
<hr>
<!--分享组件,外链mip-share.js-->
<p class="middle-text">mip-share 分享组件</p>
<mip-share title="分享:我的第一个MIP页面"></mip-share>
<hr> <!--百度统计组件,外链mip-stats-baidu.js TODO: 修改token值-->
<p class="middle-text">mip-stats-baidu 百度统计组件,代码可见</p>
<mip-stats-baidu token="4e397f684261b9e4ff9d8"></mip-stats-baidu> <!--mip 运行环境-->
<script src="https://c.mipcdn.com/static/v1/mip.js"></script>
<!--分享组件 代码-->
<script src="https://c.mipcdn.com/static/v1/mip-share/mip-share.js"></script>
<!--百度统计组件 代码-->
<script src="https://c.mipcdn.com/static/v1/mip-stats-baidu/mip-stats-baidu.js"></script>
</body>
</html>

以上参考文档:https://www.mipengine.org/doc/00-mip-101.html

MIP使用麻烦的点在于自己写组件,写完提交审核,审核反馈不通过。时间浪费了,自己多去看看规范吧。

MIP (百度移动网页加速器)的更多相关文章

  1. MIP 移动网页加速器视频教程全新发布

    MIP (Mobile Instant Pages - 移动网页加速器) 是百度推出的开源项目,用于移动端页面加速.MIP 技术通过优化浏览器资源加载,前端代码执行及 CDN 缓存加速来加速页面,打造 ...

  2. WordPress插件--WP BaiDu Submit结构化数据插件又快又全的向百度提交网页

    一.WP BaiDu Submit 简介 WP BaiDu Submit帮助具有百度站长平台链接提交权限的用户自动提交最新文章,以保证新链接可以及时被百度收录. 安装WP BaiDu Submit后, ...

  3. 调用百度、高德地图App,百度地图网页版,App定位

    https://www.jianshu.com/p/296a3995adc2 https://blog.csdn.net/qq_26598821/article/details/51087785 ht ...

  4. 新手教程:不写JS,在MIP页中实现异步加载数据

    从需求谈起:在 MIP 页中异步加载数据 MIP(移动网页加速器) 的 加速原理 除了靠谱的 MIP-Cache CDN 加速外,最值得一提的就是组件系统.所有 JS 交互都需要使用 MIP 组件实现 ...

  5. 百度MIP移动页面加速——不只是CDN

    MIP是用CDN做加速的么?准确答案是:是,但不只是. MIP全称Mobile Instant Pages,移动网页加速器,是百度提出的页面加速解决方案.MIP从前端渲染和页面网络传输两方面进行优化, ...

  6. 移动站应该尝试百度MIP的五个原因

    MIP是什么?MIP是百度在2016年提出的移动网页加速器项目. MIP能做什么?MIP能帮助站长和网站开发者快速搭建移动端页面. MIP怎么加速?MIP从前端渲染和页面网络传输两方面进行优化,杜绝页 ...

  7. 百度将与W3C中国召开MIP技术研讨会

    百度计划与W3C中国共同组织国内W3C会员,于8月30日召开MIP 技术研讨会,讨论 MIP 等技术相关的应用标准,以期推进 MIP/AMP 在W3C中国的标准化进程. MIP (Mobile Ins ...

  8. 百度站长平台MIP

    使用说明 MIP(Mobile Instant Pages - 移动网页加速器),是一套应用于移动网页的开放性技术标准.通过提供 MIP-HTML 规范.MIP-JS 运行环境以及 MIP-Cache ...

  9. 【转】W3C中国与百度联合组织移动网页加速技术研讨会

    2017 年 8 月 30 日,W3C 会员百度在北京中关村软件园国际会议中心主办了 "移动网页加速技术研讨会",W3C 中国以及腾讯.阿里巴巴及 UC.搜狗.小米.傲游.中国移动 ...

随机推荐

  1. qwe框架- CNN 实现

    CNN实现 概述 我在qwe中有两种,第一种是按照Ng课程中的写法,多层循环嵌套得到每次的"小方格",然后WX+b,这样的做法是最简单,直观.但是效率极其慢.基本跑个10张以内图片 ...

  2. 各大HotFix热补丁方案分析和比较

    最近开源界涌现了很多热补丁项目,但从方案上来说,主要包括Dexposed.AndFix.ClassLoader(来源是原QZone,现淘宝的工程师陈钟,在15年年初就已经开始实现)三种.前两个都是阿里 ...

  3. R语言︱ 数据库SQL-R连接与SQL语句执行(RODBC、sqldf包)

    要学的东西太多,无笔记不能学~~ 欢迎关注公众号,一起分享学习笔记,记录每一颗"贝壳"~ --------------------------- 数据库是极其重要的R语言数据导入源 ...

  4. FusionCharts for Flex的属性和事件

    FusionCharts for Flex的属性和事件 1.Properties(属性) (1)FCChartType (2)FCDataURL (3)FCDataXML (4)FCDebugMode ...

  5. 基于am3358的lcd输出

    /*#include<stdio.h> */ #include <unistd.h> #include <stdio.h> #include <stdlib. ...

  6. pat1121-1131

    1121 #include<cmath> #include<map> #include<iostream> #include<cstring> #inc ...

  7. BOM(浏览器对象模型)的一些操作

    一个完整的JavaScript实现由三部分组成: ECMAScript:核心,定义语言基础,规定了语言的组成部分(语法,类型,关键字,保留字,对象等) DOM:文档对象模型,·DOM把整个页面映射成一 ...

  8. numpy使用总结

    numpy是Python中常用的数据处理库的基础库,一般通过import numpy as np的方式导进 科学计算库numpy 在numpy中,主要的数据结构是ndarray,在numpy中称为数组 ...

  9. zjoi网络

    map加LCT水一下就过了 # include <stdio.h> # include <stdlib.h> # include <iostream> # incl ...

  10. vue-过滤器filter

    vue-过滤器filter vue的过滤器一般在JavaScript 表达式的尾部,由"|"符号指示: 过滤器可以让我们的代码更加优美,一般可以用在时间格式化,首字母大写等等. 例 ...