Skip to content

Instantly share code, notes, and snippets.

View erasmo-marin's full-sized avatar

Erasmo Marín erasmo-marin

  • Chile
View GitHub Profile
var express = require('express');
var app = express();
one = [ "La cueca pá los chilenos",
"Si no le gustan las cuecas",
"Hoy es 18 de Septiembre",
"Yo también voy a la ramá",
"Tu creis que no se ná",
"Yo las bailo donde sea",
"No bailo tanto pero tengo otra gracia",
@erasmo-marin
erasmo-marin / olt-ex1.jsx
Last active March 29, 2017 06:16
Optimizing the loading time for big react apps - example 1
//this is bad
import _ from "lodash";
import R from "ramda";
//pretty, but as bad as before
import { find } from "lodash";
import { compose } from "ramda";
...
import find from "lodash/find";
import compose from 'ramda/src/compose';
import curry from 'ramda/src/curry';
import map from 'ramda/src/map';
//you can do this if you want:
const _ = {
find: find
}
plugins: [
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
mangle: true,
sourcemap: false,
debug: false,
minimize: true,
compress: {
...
presets: [
["es2015", { loose: true }],
"react"
]
...
...
presets: [
["es2015", { loose: true, modules: false }],
"react"
]
...
const determineDate = () => {
import('moment').then((moment) => {
console.log(moment().format());
}).catch((err) => {
console.log('Failed to load moment', err);
});
}
determineDate();
var compression = require('compression');
var app = express();
app.use(compression());
plugins: [
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
//this middleware serves all js files as gzip
app.use(function(req, res, next) {
var originalPath = req.path;
if(!originalPath.endsWith(".js")) {
next();
return;
}
try {
var stats = fs.statSync(path.join("public", `${req.path}.gz`));
res.append('Content-Encoding', 'gzip');