• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koajs/bigpipe-example: [DEPRECATED] BigPipe using koa and component

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

koajs/bigpipe-example

开源软件地址:

https://github.com/koajs/bigpipe-example

开源编程语言:

JavaScript 81.7%

开源软件介绍:

BigPipe Example Build Status

An app built with koa and component that implements Facebook's BigPipe.

Given a subreddit, this app does the following:

  • An image grid based on horizontal-grid-packing of the latest imgur posts.
  • Show you the title of the subreddit and the number of subscribers.
  • Show you the top 5 posts within the past day, week, month, year, and all time.

In total, that is 7 asynchronous calls with the request to imgur being the slowest.

Installation and Setup

This example requires node v0.11.3+ for generator support. Here's an example installation:

# Install and use node v0.11
nvm install 0.11
nvm use 0.11

# Clone this example
git clone git://github.com/jonathanong/bigpipe-example
cd bigpipe-example

# Install all dependencies and build the assets
npm install

# Start the server. Serves on port 3456 by default
npm start

Strategies

This example implements 3 strategies. The strategies are listed from slowest to fastest and worst to best. This app is designed to be able to switch between any of these 3 modes with minimal code.

These strategies are all implemented as streams. If you want to implement caching, you would want to buffer the result and process it before sending it to the client. Fortunately, this is easy with koa.

Sequential

All asynchronous functions are blocking and are called within the template. This is the easiest way to build a webpage and is similar traditional web languages like PHP, Ruby, and Python. This is actually difficult to do in vanilla node.js, but very easy with koa.

Parallel

All asynchronous functions are executed before the rendering of the template. This is similar to traditional Express apps where rendering occurs at res.render() (assuming the developer executes the functions in parallel). This is the ideal method if you intend to cache the page.

BigPipe

All asynchronous functions are executed after the initial layout is flushed to the client so the client will see a barebone layout immediately. Each asynchronous function, also called a pagelet, is rendered and pushed independently to the client. Each pagelet is generally self-contained, meaning it has its own HTML, JS, CSS.

The major downside to BigPipe is that it requires Javascript on the client and HTTP caching is pretty much impossible. BigPipe should be used only for dynamic content.

Koa

Koa is a new generator-based framework based on co and is the spiritual successor to express. By using generators for control flow, there's no more callback hell or painful error handling. Look at the source code to see for yourself.

Component

Component is a CommonJS-based client-side package manager and build system. Not only does it allow you to easily consume 3rd party components (packages of JS, CSS, HTML, images, fonts, etc.), it also allows you to organize your app as independent components. No more /scripts, /styles, /images, and /templates folders where finding what you need is difficult. View the /client to see how apps should be structured.

Architecture

  • client/ - all client-side CSS and JS that is not within a View.
  • routes/ - all routes.
  • view/ - base constructor which all Views inherit from.
  • views/ - all the different views.

License

The MIT License (MIT)

Copyright (c) 2013 Jonathan Ong [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap