商城系统app开发如何满足不断变化的市场需求与用户期待
662
2022-11-05
Staticgen - 静态网站生成器,可让您使用已知的HTTP服务器和框架
Staticgen
A static website generator that lets you use HTTP servers and frameworks you already know. Just tell Staticgen how to start your server, then watch it crawl your site and generate a static version with all of the pages and assets required.
About
If you're unfamiliar, you can actually use the decades-old wget command to output a static website from a dynamic one, this project is purpose-built for the same idea, letting your team to use whatever HTTP servers and frameworks you're already familiar with, in any language.
I haven't done any scientific benchmarks or comparisons yet, but here are some results on my 2014 8-core MBP:
Compiles 3,296 pages of the Signal v. Noise blog in 1 secondCompiles my Apex Software site in 150ms
Installation
Via gobinaries.com:
$ curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh
Configuration
Configuration is stored within a ./static.json file in your project's root directory. The following options are available:
command — The server command executed before crawling.url — The target website to crawl. Defaults to "http://127.0.0.1:3000".dir — The static website output directory. Defaults to "build".pages — A list of paths added to crawl, typically including unlinked pages such as landing pages. Defaults to [].concurrency — The number of concurrent pages to crawl. Defaults to 30.
Guide
First create the ./static.json configuration file, for example here's the config for Go server, the only required property is command:
{ "command": "go run main.go", "concurrency": 50, "dir": "dist"}
Below is an example of a Node.js server, note that NODE_ENV is assigned to production so that optimizations such as Express template caches are used to improve serving performance.
{ "command": "NODE_ENV=production node server.js"}
Run the staticgen command to start the pre-rendering process:
$ staticgen
Staticgen executes the command you provided, waits for the server to become available on the url configured. The pages and assets are copied to the dir configured and then your server is shut down.
By default the timeout for the generation process is 15 minutes, depending on your situation you may want to increase or decrease this with the -t, --timeout flag, here are some examples:
$ staticgen -t 30s$ staticgen -t 15m$ staticgen -t 1h
When launching the command, Staticgen sets the STATICGEN environment variable to 1, allowing you to alter behaviour if necessary.
To view the pre-rendered site run the following command to start a static file server and open the browser:
$ staticgen serve
See the examples directory for full examples.
Notes
Staticgen does not pre-render using a headless browser, this makes it faster, however it means that you cannot rely on client-side JavaScript manipulating the page.
Sponsors
This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.
And my GitHub sponsors:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~