Show HN:我在浏览器中 100% 制作了 HTMX Playground
Show HN: I made a HTMX Playground 100% in the browser

原始链接: https://lassebomh.github.io/htmx-playground/

隆重推出 HTMX Playground - 专为 HTMX 用户设计的交互式编码空间。 无需设置,只需访问该网站,使用预定义的示例探索其功能,或通过调整原始 htmx.org 示例来创建您的独特代码。 与代码在服务器上运行的传统后端不同,HTMX Playground 允许您完全在浏览器中试验前端编程,同时仍然允许您通过模拟服务器设置配置路由并创建自定义 HTML 响应。 要保存或共享您的工作,请单击“复制为 JSON”,通过 Github 上传或插入提供的链接,然后该链接会将代码显示为实时演示。 有几点需要注意:该平台不允许真正的网页浏览,这使得它比标准网页更不适合移动设备。 此外,由于初始网站内容在 iFrame 内加载,因此之后所做的任何修改不一定会持续存在,除非它们发生在第一个网页加载过程中。 与此程序相关的一些流行库包括 Svelte、PollyJS 和 Nunjucks。 在 GitHub 上了解有关其功能的更多信息。

HTMX 将超媒体控制原语的抽象添加到 HTML,例如使任何元素发送和接收 HTTP 请求以及动态地用另一个元素替换 HTML 文档的任何部分(易位)的能力,同时在这些操作之间保持 DOM 完整,提供 一种强大而直观的方法,用于仅使用普通 HTML 和 JavaScript 创建丰富而复杂的应用程序。 虽然 InterCooler 是一个 JavaScript 库,可以使用 AJAX 创建动态 Web 应用程序,但它不能直接与 HTMX 相比较,尽管它与 HTMX 具有某些共同点,特别是在将表示问题与业务逻辑问题分离的理念方面。 最终,虽然目标有些一致,但 HTMX 在简单性、可用性、灵活性、表现力、性能、可扩展性以及整体质量和完整性方面比早期技术取得了重大进步,而 InterCooler 主要侧重于解决 HTML 中的差距和缺点 它在首次引入时就存在,即通过 AJAX 进行客户端交互。 因此,HTMX 既不是 InterCooler 的直接替代品,也不是 InterCooler 的严格超集,而是代表了对解决当代 Web 开发中常见技术挑战和障碍的先前方法的重大改进。
相关文章

原文
"Finally a way to use HTMX as a SPA framework"
Hackernews commenter

HTMX Playground is a simple code sandbox for playing around with HTMX. No setup needed!

Check out the examples! I've adapted them from the original htmx.org examples.

It allows you to write code in a backend-like environment, running entirely inside the browser. You can define endpoints within server.js and render your own templates. It will run a mock server that intercepts outgoing requests from HTMX. The request handling and templating engine should be very familiar to people who use Django. In principle, this project isn't specific to HTMX, so you are free to try out other libraries as well.

Saving & sharing

  1. Press "Copy as JSON" in the top right.
  2. Upload the contents as a Gist, and enter the raw URL in "Load Playground"
  3. The URL on this page will update, and can now be shared.

The code is available on GitHub.

Caveats

  • No page navigation
  • Limited mobile support

Additionally, server.js can be stateful (such as in the Click to Edit example), but any update to the state in the on.get("/") view will be lost. This is due to the fact that the initial page load is retrieved in a seperate iframe, before updating the on-screen iframe.

Libraries used

  • Svelte
  • Ace (code editor)
  • PollyJS (mock server)
  • Nunjucks (templating engine)
联系我们 contact @ memedata.com