Coder Social home page Coder Social logo

kriasoft / pre-render Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 4.0 26 KB

Convert a single-page app (SPA) into a fully pre-rendered functional website before deploying it to a CDN

License: MIT License

JavaScript 100.00%
single-page-app single-page-applications seo rendering pre-rendering react reactjs vue vuejs ssr

pre-render's Introduction

pre-render   NPM Package NPM Downloads NPM Dependencies

Instead of building an isomoprhic app (with SSR - server-side rendering), it's sometimes easier to create a normal single-page web application (SPA) by using a modern front-end library such as React, Vue.js etc (see example). But what about SEO, initial page load time, and other optimizations?

The goal of this project is to generate static .html pages for your single-page app at build time, before you deploy it to a CDN hosting. You just build your project as normal, assuming that it compiles into the /build (or /dist) folder, then prepare the list of relative URL paths that need to be pre-rendred and pass that info to pre-render, it will load /build/index.html in a headless Chrome browser, iterate over the list of provided relative URLs and save each page to a corresponding .html file.

How to Use

You need to tweak your app, to expose window.prerender handler, that may look something like this:

window.preprender = async path => {
  history.push(path);
  /* make sure that the client-side rendering is complete, then */
  return document.documentElement.outerHTML;
};

Then build your project (npm run build) and run the following script:

const prerender = require('pre-render');

prerender('./build', [
  '/',
  '/about',
  /* ... */
]);

Now, you can deploy the contents of the /build folder to GitHub Pages, Firebase, or some other CDN hosting, yet search engines will still be able to crawl your site.

License

Copyright © 2017-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE.txt file.


Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors

pre-render's People

Contributors

koistya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pre-render's Issues

Instead of rendering each page under a folder, can be without?

I get all rendered like this mypage.html/index.html. Then some url start looking weird and I get sometimes on the live site with www.xxx.com/mypage.html/ and www.xxx.com/mypage.html. They are the same page but one has a slash at the end the other not.

I wonder if I can make them all without slash at the end.

Thanks

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.