• Stars
    star
    2,230
  • Rank 20,651 (Top 0.5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight JS framework for fast navigation and page updates from YouTube

SPF

Version Status InlineDocs

Structured Page Fragments — or SPF for short — is a lightweight JS framework for fast navigation and page updates from YouTube.

Using progressive enhancement and HTML5, SPF integrates with your site to enable a faster, more fluid user experience by updating just the sections of the page that change during navigation, not the whole page. SPF provides a response format for sending document fragments, a robust system for script and style management, an in-memory cache, on-the-fly processing, and more.

Learn more at youtube.github.io/spfjs

Overview

SPF allows you to leverage the benefits of a static initial page load, while gaining the performance and user experience benefits of dynamic page loads:

User Experience

  1. Get the fastest possible initial page load.
  2. Keep a responsive persistent interface during navigation.

Performance

  1. Leverage existing techniques for static rendering.
  2. Load small responses and fewer resources each navigation.

Development

  1. Use any server-side language and template system.
  2. Be productive by using the same code for static and dynamic rendering.

Download

Install with npm:

npm install spf

Install with Bower:

bower install spf

Or, see the download page for options to download the latest release and link to minified JS from a CDN:

Download SPF

Get Started

The SPF client library is a single ~10K UMD JS file with no dependencies. It may be asynchronously delay-loaded. All functions are exposed via the global spf object.

Enable SPF

To add SPF to your site, include the JS file and run spf.init().

<script>
  spf.init();
</script>

Send requests

SPF does not change your site's navigation automatically and instead uses progressive enhancement to enable dynamic navigation for certain links. Just add a spf-link class to an <a> tag to activate SPF.

Go from static navigation:

<a href="/destination">Go!</a>

to dynamic navigation:

<!-- Link enabled: a SPF request will be sent -->
<a class="spf-link" href="/destination">Go!</a>

Return responses

In static navigation, an entire HTML page is sent. In dynamic navigation, only fragments are sent, using JSON as transport. When SPF sends a request to the server, it appends a configurable identifier to the URL so that your server can properly handle the request. (By default, this will be ?spf=navigate.)

In the following example, a common layout of upper masthead, middle content, and lower footer is used. In dynamic navigation, only the fragment for the middle content is sent, since the masthead and footer don't change.

Go from static navigation:

GET /destination

<html>
  <head>
    <!-- Styles -->
  </head>
  <body>
    <div id="masthead">...</div>
    <div id="content">
      <!-- Content -->
    </div>
    <div id="footer">...</div>
    <!-- Scripts -->
  </body>
</html>

to dynamic navigation:

GET /destination?spf=navigate

{
  "head": "<!-- Styles -->",
  "body": {
    "content":
        "<!-- Content -->",
  },
  "foot": "<!-- Scripts -->"
}

See the documentation for complete information.

Browser Support

To use dynamic navigation, SPF requires the HTML5 History API. This is broadly supported by all current browsers, including Chrome 5+, Firefox 4+, and IE 10+. See a full browser compatibility table at Can I Use. Underlying functionality, such as AJAX-style page updates and script/style loading, is more broadly supported by IE 8+.

Get Help

Send feedback, comments, or questions about SPF to [email protected].

File bugs or feature requests at GitHub.

Join our mailing list and follow @spfjs on Twitter for updates.

License

MIT
Copyright 2012-2017 Google, Inc.

More Repositories

1

api-samples

Code samples for YouTube APIs, including the YouTube Data API, YouTube Analytics API, and YouTube Live Streaming API. The repo contains language-specific directories that contain the samples.
Java
5,477
star
2

doorman

Doorman: Global Distributed Client Side Rate Limiting.
Go
1,910
star
3

youtube-ios-player-helper

Lightweight helper library that allows iOS developers to add inline playback of YouTube videos through a WebView
Objective-C
1,650
star
4

spitfire

A high-performance Python template language
Python
406
star
5

yt-watchme

Java
340
star
6

cobalt

Cobalt is a lightweight HTML5 application container
C++
296
star
7

yt-direct-lite-android

The code is a reference implementation for an Android OS application that captures video, uploads it to YouTube, and submits the video to a YouTube Direct Lite instance.
Java
276
star
8

yt-direct-lite-iOS

The code is a reference implementation for an iOS application that captures video, uploads it to YouTube, and submits the video to a YouTube Direct Lite instance.
Objective-C
202
star
9

geo-search-tool

A tool to perform YouTube API v3 searches for videos tagged with geo-coordinates.
JavaScript
138
star
10

yt-android-player

Java
130
star
11

js_mse_eme

js_mse_eme is an externally-published tool that is aimed to test the validity of a browser's HTML5 Media Source Extension and Encrypted Media Extension implementations
JavaScript
91
star
12

youtubechatbot

This is a sample YouTube chat bot that's designed to run on Google App Engine. It leverages Task Queues to simulate a long-running background process which polls the YouTube LiveChatMessages API for the specified video.
83
star
13

youtube-chat-for-minecraft

A plugin for Minecraft Forge that provides an API for YouTube live chat services
Java
60
star
14

h5vcc

This is a minimal build of WebKit and Chromium sufficient to render an HTML5 video container for game consoles.
C++
58
star
15

yt-direct-lite-javascript

JavaScript
32
star
16

cobalt_sandbox

Cobalt dev workflow sandbox - this repo exists only as a CI sandbox. Please see http://cobalt.dev and https://github.com/youtube/cobalt
C++
21
star
17

yt-auto-curate-ruby

Ruby
15
star
18

h5vcc_hh

C++
15
star
19

yt-analytics-dump-ruby

Ruby
10
star
20

yt-shuffle-playlist-ruby

Ruby
10
star
21

rcat

A proposal for detecting engagement abuse of embedded third-party web content without depending on cookies.
Java
7
star
22

yt_channel_section_targeter

HTML
6
star
23

vfl

5
star
24

.github

3
star
25

.allstar

1
star