# spfjs **Repository Path**: tpi/spfjs ## Basic Information - **Project Name**: spfjs - **Description**: Mirror of https://github.com/youtube/spfjs.git - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2020-08-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # [![SPF][]](https://youtube.github.io/spfjs/) [![Version][]](https://badge.fury.io/js/spf) [![Status][]](https://travis-ci.org/youtube/spfjs) [![InlineDocs][]](https://inch-ci.org/github/youtube/spfjs) 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][]: ```sh npm install spf ``` Install with [Bower][]: ```sh 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](https://youtube.github.io/spfjs/download/) ## 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()`. ```html ``` **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 `` tag to activate SPF. Go from static navigation: ```html Go! ``` to dynamic navigation: ```html Go! ``` **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