Can I knit a minimal html without bloat?

Even an almost RMarkdown can be rendered to a html in about 700kb. I understand it's a standalone file packed all the js libs etc so it doesn't depend on other files.

Sometimes ago I was able to make it much smaller by declaring mathjax: null in yaml header. Now this doesn't make any change.

Is there any known method to render minimal html if I don't need mathjax etc?

Hadley mentioned html_vignette() a little while ago:

According to that page:

So, that might be what you're looking for, or at least provide a basic starting point that you can customize further if needed.


Try adding theme: null and highlight: null to the YAML front matter. This will result in a 1.5 kb HTML file (without content of course). From there you can do theme: pygments which will give you some syntax highlighting and take the file size up to 3.8 kb. If you go with the default highlighting you'll be up to 44 kb.

From there you can add a css field to style as desired and end up with a pretty lightweight document.


Thanks for the tips!

I did try theme:null before, but found that feel too "90s". Customizing a good theme is not easy, fortunately I found prettydoc. It solved my problem completely.

The html_document engine uses the Bootswatch theme library to support different styles of the document. This is a quick and easy way to tune the appearance of your document, yet with the price of a large file size (> 700KB) since the whole Bootstrap library needs to be packed in.

For package vignettes, we can use the html_vignette engine to generate a more lightweight HTML file that is meant to minimize the package size, but the output HTML is less stylish than the html_document ones.

So can we do BOTH, a lightweight yet nice-looking theme for R Markdown?

A simple document with some table took about 60k, support syntax highlighting.

This is good enough, and I can select from several themes.


Funny thing is, in the end I returned to default theme because I want floating toc. And the extra file size become relative insignificant when I need to embed plots pictures.