Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions common/components/TodoApp.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { Component, PropTypes } from 'react';
import DevTools from './DevTools';

if ( 'undefined' !== typeof window ) {
require( '../../client/assets/css/main.css' );
}

export default class TodoApp extends Component {

static contextTypes = {
Expand Down
22 changes: 19 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ app.use( ( req, res, next ) => {

.then( () => {

return new Promise((resolve, reject) => {
fs.readFile('./client/assets/css/main.css', 'utf8', (err, data) => {
if (err) {
reject(err);
return;
}
resolve(data);
});
});

})

.then( (criticalCSS) => {

const initView = renderToString((
<Provider store={store}>
<RouterContext {...renderProps} />
Expand All @@ -76,7 +90,9 @@ app.use( ( req, res, next ) => {
let state = JSON.stringify( store.getState() );
// console.log( '\nstate: ', state )

let page = renderFullPage( initView, state )


let page = renderFullPage( initView, state, criticalCSS )
// console.log( '\npage:\n', page );

return page;
Expand All @@ -89,15 +105,15 @@ app.use( ( req, res, next ) => {
})
})


function renderFullPage(html, initialState) {
function renderFullPage(html, initialState, criticalCSS) {
return `
<!doctype html>
<html lang="utf-8">
<head>
<title>Universal Redux Example</title>
<link rel="shortcut icon" type="image/png" href="assets/images/react.png">
<link rel="stylesheet" href="/assets/css/uikit.almost-flat.min.css">
<style type="text/css">${criticalCSS}</style>
</head>
<body>
<div class="container">${html}</div>
Expand Down