未加星标

A trick to make your big dataviz load super fast

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Big datasets are fun. The bigger, the better, especially when you let people explore them live in their browser.

But there’s a catch: big datasets are slow to load.

Even with modern content delivery networks (CDNs), gzip compression, and high internet speeds, it can take a few seconds to load and parse a dataset. In my H1B salaries visualization , downloading data takes 1.7 seconds, parsing takes another 2 seconds, and rendering takes maybe a full second because some things are done stupidly.

That’s a full 4 to 5 seconds before a user sees anything more than a "Loading, please wait” message. Users are going to leave before they play with your dataset. Yes, even though it’s so cool and the data is amazing and awesome, users don’t give a shit. It’s sad.

But there’s a trick to keep them around → show them an image first!

Check this out:


A trick to make your big dataviz load super fast

See how you barely notice the page refresh? That’s on purpose.

The main App.render() method is wrapped in a conditional statement that checks if the data is available. If it is, then we render the interactive visualization; if it isn’t, then we render a screenshot and default descriptions.

// src/App.js render() { if (this.state.techSalaries.length < 1) { return ( <Preloader /> ); } // render the main dataviz }

The Preloader component can be a functional stateless component, like this:

// src/App.js import StaticViz from './preloading.png'; const Preloader = () => ( <div className="App container"> <h1>The average H1B in tech pays $86,164/year</h1> <p className="lead">Since 2012 the US tech industry has sponsored 176,075 H1B work visas. Most of them paid <b>$60,660 to $111,668</b> per year (1 standard deviation). <span>The best city for an H1B is <b>Kirkland, WA</b> with an average individual salary <b>$39,465 above local household median</b>. Median household salary is a good proxy for cost of living in an area.</span></p> <img src={StaticViz} style={{width: '100%'}} /> <h2 className="text-center">Loading data ...</h2> </div> );

The Preloader component mimics the structure of your normal dataviz, but it’s hardcoded. The information is real, and it’s what people are looking for, but it doesn’t need the dataset to render.

The easiest way to get this is to first build your real dataviz, then screenshot the picture, and then copy-paste the descriptions if they’re dynamic. Without dynamic descriptions, half your job is done already.

That’s about it, really:

render an image wait for data to load replace image with dynamic dataviz

It sounds dumb, but increases user satisfaction 341324%.

If it works …


A trick to make your big dataviz load super fast

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: CDN
分页:12
转载请注明
本文标题:A trick to make your big dataviz load super fast
本站链接:http://www.codesec.net/view/484038.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(34)