Giter VIP home page Giter VIP logo

prpl-html's Introduction

PRPL HTML

An experiment implementing the PRPL pattern with HTML files.

See

Visit the deployed site to get a feel for how the mechanism works.

Why

Typically this pattern is used to prefetch things like JavaScript bundles or JSON required to construct the DOM for the next page. I thought it might be interesting to boil it down further and prefetch the actual html of the next page.

How it works

  1. Initial html file is loaded by the browser
  2. After the page is loaded, we grab an achor tag that points to another html file and fetch it
  3. After that page is fetched, we save the html string in local storage
  4. Still on the initial html file, we add an event listener to listen for clicks on that anchor tag
  5. When a user clicks on that anchor tag, we tell the browser not to load it normally. Then, we take the href attribute and get the item we fetched earlier in local storage.
  6. Now that we have the html string for the file we want to navigate to, we use the DOMParser interface to parse it into a document
  7. Finally, we replace the current document body with the target document body

Thoughts

  • Using local storage needs further consideration:
    • Storage item size
    • Number of storage items
    • Read/write speed
    • Sites or users that disable local storage
  • Should use a smarter technique to determine which links to prefetch and when to do it
  • Should do the prefetch in a worker to offload work to another thread

prpl-html's People

Contributors

tyhopp avatar

Stargazers

 avatar

Watchers

 avatar  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.