@matthewcp
Perceived performance: no one likes staring at a spinner.
This sucks
SEO: if you care about that sort of thing, it helps. Not every bot is Googlebot.
BLING BLING: Amazon reports that conversion increased by 1% for every 100ms improvement.
PhantomJS
Looks like a real DOM, only the basics
/cart
Title
/cart
Title
/cart
Title
import Framework from 'fancy-framework';
import './styles.scss';
...
<script>
INLINE_CACHE = {"users": [{ ... } ] };
</script>
var ssr = require("can-ssr/middleware");
var app = require("express")();
app.use(ssr());
Middleware
var ssr = require("can-ssr");
var render = ssr();
render("/cart").then(function(result){
console.log(result.html);
});
Core API
export function createState(request){
// url could be: /, /profile, /messages, etc.
const page = request.url.split("/").pop() || "home";
return {
page: page
};
}
export function render(document, state){
$("<title>").text("jQuery App").appendTo(document.head);
let body = $(document.body);
body.append(template());
// Show the tab selected in the state
body.find(`[aria-controls=${state.page}]`).tab("show");
}
// server.js
import render from "framework-dom";
app.get("/cart", function(req, res){
fetchCart().then(function(data){
res.send(
render(data)
);
});
});
// cart.js
import Component from "fancy-framework";
class Cart extends Component {
render() {
let data = this.props.data;
return <div> ... </div>
}
}