HotDocs: Static export
Create a static build with Parklife:
bundle add --group development parklife
bundle exec parklife init --rails
- Update
Parklife
- Update
bin/static-build
bin/static-build
You can test the static export with:
ruby -r webrick -e 'WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: "build").start'
Refer to the Parklife docs for details on how to tweak the configuration.
Fetch fresh content
There are situations where a static build is limiting. For example, you may have a page that loads some data from the database:
Registered users: #{User.registered.count}
If you exported that page from a development environment, the count would be wrong. And, even if you managed to export it from the production database, the count would be outdated.
You can work around this issue by using the fetcher
helper:
After setting fetcher_host
in hotdocs_helper.rb
, wrap content in a fetcher
block to fetch dynamic content from the backend.
rack-cors
.
For example, given the following is statically exported:
<%= fetcher(id: "someid", path: "/my/path", fallback: "Registered users: Loading...") do %>
Registered users: #{User.registered.count}
<% end %>
- On the first load, the fallback is rendered:
Registered users: Loading...
- the fetcher gets
fetcher_host + path
, which is expected to contain either:
<%= fetcher(id: "someid", path: "/my/path", fallback: "Registered users: Loading...") do %>
Registered users: #{User.registered.count}
<% end %>
or an element with the correct id:
<div id="someid">
Registered users: #{User.registered.count}
</div>
- the content is swapped:
- Registered users: Loading...
+ Registered users: #{User.registered.count}