knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

minifyr

Lifecycle: experimental R-CMD-check

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")
minifyr_example("html")
minifyr_example("json")
minifyr_example("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
minifyr::minifyr_css_cleancss("test.css", "test2.css")
minifyr::minifyr_css_cleancss("test.css", "test2.css")
cat test2.css

Note that all minifiers do not minify the same way

minifyr::minifyr_css_crass("test.css", "test3.css")
minifyr::minifyr_css_crass("test.css", "test3.css")
cat test3.css

{bash, echo=FALSE} rm test.css test2.css test3.css



ColinFay/minifyr documentation built on June 29, 2023, 3:39 a.m.