GithubHelp home page GithubHelp logo

simplewebpguide's Introduction

1.日常针对图片资源做的一些优化

  • 图片优化的点:
  • 1.根据业务场景不同选择对应的JPG,PNG,GIF等格式
  • 2.设计给到图片后首先自己用 TinyPNG4MAC 进行压缩
  • 3.小 icon 使用 iconfont
  • 4.小图使用 base64 打进 html 文档中,webpack 模式的阈值是 5kb
  • 5.懒加载
  • 6.动静分离,从主域名上进行剥离
  • 7.使用 webp
  • ...

2.使用 weibp 图片的一个流程

  • 1.判断浏览器是否支持 webp 格式
  • 2.支持则去加载 webp 的图片
  • 3.服务器上有 webp 格式的图片则load之,渲染之
  • 4.服务器上没有触发 @error 方法,加载 originPic
  • 5.渲染常规格式的图片

3.运行本项目

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

4.没有做的一些优化点

  • 1.获取浏览器支持应该只获取一次,然后将状态值存到 store 或 cookie 中,共享之
  • 2.服务器通过请求头 Accept: image/webp,image/apng,image/, 去判断客户端是否支持 webp 按需返回格式
  • 3.大规模使用需要服务器端进行支持,本项目仅作为一个尝鲜的demo示例

simplewebpguide's People

Contributors

iplaycodex avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.