README.md

minifyr

Lifecycle:
experimental

Extremely high-speed network infrastructures are becoming more and more popular in developed countries. However, we still face crowded and low-speed Wi-Fi environments on airport, cafe, international conference, etc. Especially, a network environment of mobile devices requires efficient usage of network bandwidth.

Empirical Study on Effects of Script Minification and HTTP Compression for Traffic Reduction, http://www27.cs.kobe-u.ac.jp/achieve/data/pdf/1198.pdf

The goal of {minifyr} is to provide a wrapper around the node-minify NodeJS module.

This package bundles the whole NodeJS minifiers, so that they can be run from R.

More background info at: colinfay.me/node-r-package/

Installation

You can install the dev version of {minifyr} with:

remotes::install_github("colinfay/minifyr")

NOTE: YOU WILL NEED NODEJS ON YOUR MACHINE

Example

Install the Node deps

You’ll need to run this once:

# Check node and npm are available
minifyr::node_available()
# Will install the node dependencies
minifyr::minifyr_npm_install()

Note

For now, all the Node functions are called with their default arguments.

Minifying CSS

Minifying HTML

Minify JS

Minify JSON

Minifyr example

minifyr comes with a series of examples:

library(minifyr)
minifyr_example("css")
[1] "/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpW8h6s4/file839381dce1d.css"
minifyr_example("html")
[1] "/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpW8h6s4/file8392cc6eeb3.html"
minifyr_example("json")
[1] "/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpW8h6s4/file839386140bc.json"
minifyr_example("js")
[1] "/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpW8h6s4/file83978e1138e.js"

Note that files are copied to a tempfile so that you don’t accidentally erase the original files.

Example

echo "body {
  margin: 25px;
  background-color: rgb(240,240,240);
  font-family: arial, sans-serif;
  font-size: 14px;
}" >> "test.css"
cat test.css
body {
  margin: 25px;
  background-color: rgb(240,240,240);
  font-family: arial, sans-serif;
  font-size: 14px;
}
minifyr::minifyr_css_cleancss("test.css", "test2.css")
cat test2.css
body{margin:25px;background-color:#f0f0f0;font-family:arial,sans-serif;font-size:14px}

Note that all minifiers do not minify the same way

minifyr::minifyr_css_crass("test.css", "test3.css")
cat test3.css
body{background-color:#f0f0f0;font-family:arial,sans-serif;font-size:14px;margin:25px}


ColinFay/minifyr documentation built on July 23, 2020, 12:33 a.m.