Git Product home page Git Product logo

spfjs's Introduction

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.

spfjs's People

Contributors

amzotti avatar awbraunstein avatar brainiac86 avatar davidcphillips avatar escholtz avatar hanqingl avatar marcelduran avatar mikeathene avatar nanaze avatar nicksay avatar philharnish avatar pope avatar rrrene avatar rviscomi avatar slavejovanovski avatar tchiotludo avatar zhaoz avatar

Watchers

 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.