How to provide a web site as a single file?

不羁的心 提交于 2019-12-11 07:06:17

问题


I have a bare-metal application running on a tiny 16 bit microcontroller (St10) with 10BASE-T Ethernet (CS8900) and a Tcp/IP implementation based upon the EasyWeb project.

There is a tiny webserver implemented for displaying some status information of the device and also allows to change settings et cetera.

For browser access, the webserver provides some files like index.html, *.css, *.js, *.svg, *.png and so on.

As the bare-metal target has no storage media like a sd-card, I put all of the above mentioned resources into the compiled binary.

For saving memory and reducing traffic, I put all of the files together into a single index.html compress that using gzip and let my webserver deliver this using Content-Encoding: gzip.

The step to put all the files together into single index.htm is currently manual work (incl. replace filename references et cetera). Might there be a tool which do this automatically?

Or alternatively, can I just zip / tar / whatever all the files into a single file and deliver this upon http GET / request?

Edit 2017-10-05

Solved by using the inliner mentioned by brain99.

Having small trouble making it run on Kubuntu 16.04 host but finally fixed it by installing:

sudo apt-get install nodejs
sudo ln -sT "$(which nodejs)" /usr/local/bin/node
sudo apt-get install npm
sudo npm install -g inliner

Maybe, I'd got rid of the symlink by using nodejs-legacy instead of nodejs (have not tried). After having installed that, I just need to run:

inliner index.html >index-backed.html
gzip -c index-backed.html >index.html.gz

回答1:


Option 1: via Chrome

There is a set of two Chrome extensions that allow you to save a webpage to a single HTML file:

  • SingleFile
  • SingleFile Core

The second extension is a helper extension required by the first one. I did not test this, but it seems to have reasonably good reviews in the Chrome web store (apparently it can choke on complex pages).

With these extensions, you should just be able to open the page in Chrome and use the extensions to save as a single file with embedded CSS/scripts/images.

Option 2: scriptable

If you want to automate things in a script, there is also a project on github exactly for that, which can be installed via npm.




回答2:


I am a little confused on what you want to do but I am guessing you need a way to save some storage, one thing that you could maybe try in storing some files in Google Drive? That way, you don't have to worry about the files on there, you just upload your images, and pull them from drive like this:

<img src="https://drive.google.com/uc?export=download&id=YOUR_FILE_ID">

Of course replace YOUR_FILE_ID with your actual file ID, get that by using the share link for Google Drive. Like this:

https://drive.google.com/file/d/YOUR_FILE_ID/view?usp=sharing

I would find this a better solution than zipping it, but the choice is yours, hope this helps you!



来源:https://stackoverflow.com/questions/46379586/how-to-provide-a-web-site-as-a-single-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!