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/
You can install the dev version of {minifyr}
with:
remotes::install_github("colinfay/minifyr")
NOTE: YOU WILL NEED NODEJS ON YOUR MACHINE
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()
For now, all the Node functions are called with their default arguments.
minifyr_css_cleancss()
minifyr_css_crass()
minifyr_css_cssnano()
minifyr_css_csso()
minifyr_css_sqwish()
minifyr_css_yui()
minifyr_html_minifier()
minifyr_js_babel()
minifyr_js_gcc()
minifyr_js_terser()
minifyr_js_uglify()
minifyr_js_yuiy()
minifyr_json_jsonminify()
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.
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}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.