Conditionally loading mini SheetJS module
However you present data in your web application, some users will want to export the data so that they can manipulate it with their preferred tools such as Excel or R.
Excel supports several file formats. Users would be happy with any file type as long as the exported data can be opened in Excel in one click. If users want to preserve the data types in the exported data .xlsx format is the best option. Export into pure text files such as .csv might cause dispensable problems. For example, dates might be imported into Excel as strings or strings might be automatically converted to numbers or dates. Still, .csv files have a prominent advantage — if the you export data into .csv, you do not really need to use any libraries.
Unlike text files, .xlsx files have a complicated format. But you do not need to understand it if you only want let users export the data from their browsers into Excel files. There are free libraries converting two-dimensional arrays into Excel sheets. SheetJS is a straightforward library for reading and creating Excel files of any format in a browser. As any library, SheetJS has an innate disadvantage — it has size that has to be loaded to a browser. In this post I focus on mini SheetJS, a smaller version of SheetJS, and explore how not to load it always even when it is not…