Htmx: HTML 的强大工具
Htmx: High Power Tools for HTML

原始链接: https://github.com/bigskysoftware/htmx

## htmx:用现代Web能力扩展HTML htmx是一个轻量级(14kb 压缩后)JavaScript库,它极大地扩展了标准HTML的功能。它允许开发者通过HTML属性直接访问AJAX、CSS过渡、WebSockets和服务器发送事件,从而消除了对许多常见Web交互中复杂JavaScript框架的需求。 本质上,htmx通过使*任何*元素能够通过*任何*事件触发HTTP请求,并使用比完整页面刷新更精细的方式交换内容,来挑战传统HTML的限制。 通过简单的属性,如`hx-post`和`hx-swap`,你可以用最少的代码构建动态用户界面。htmx没有依赖,可扩展,并且是intercooler.js的后继者。它可以通过CDN或npm (`npm install htmx.org --save`)获得,并积极鼓励社区贡献和赞助。

## HTMX:在Hacker News上日益火热 最近Hacker News上的讨论突显了人们对HTMX的兴趣日益增长,HTMX是一个为HTML添加动态行为的库。BigSky Software公司的CEO(HTMX的开发公司)表达了对社区支持的感谢,并概述了未来的开发计划。 对话的中心是HTMX是否适用于大型应用程序。它并非React等完整框架的替代品,但可以逐步添加到现有代码库中,即使是拥有数百万行代码的代码库。用户报告称,他们成功地使用HTMX重写了React应用程序,通常与Alpine.js结合使用以实现响应式。 一个关键的好处是将复杂性转移回服务器端,从而简化前端开发。然而,HTMX依赖于服务器端HTML渲染,并且可能需要针对基于JSON的API进行变通。一些用户注意到它“有点傻气”,以及其创造者不同寻常的方法。尽管如此,许多人发现它能提高生产力,并为复杂的JavaScript框架提供了一种令人耳目一新的替代方案,尤其是在CRUD应用程序和内部工具方面。讨论还涉及该库在Hacker News上被频繁“重新发现”,表明其采用率正在增长。
相关文章

原文

</> htmx

high power tools for HTML

Discord Netlify Bundlephobia Bundlephobia

htmx allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext

htmx is small (~14k min.gz'd), dependency-free & extendable

  • Why should only <a> and <form> be able to make HTTP requests?
  • Why should only click & submit events trigger them?
  • Why should only GET & POST be available?
  • Why should you only be able to replace the entire screen?

By removing these arbitrary constraints htmx completes HTML as a hypertext

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/htmx.min.js"></script>
  <!-- have a button POST a click via AJAX -->
  <button hx-post="/clicked" hx-swap="outerHTML">
    Click Me
  </button>

The hx-post and hx-swap attributes tell htmx:

"When a user clicks on this button, issue an AJAX request to /clicked, and replace the entire button with the response"

htmx is the successor to intercooler.js

installing as a node package

To install using npm:

npm install htmx.org --save

Note there is an old broken package called htmx. This is htmx.org.

Want to contribute? Check out our contribution guidelines

No time? Then become a sponsor

To develop htmx locally, you will need to install the development dependencies.

Run:

Then, run a web server in the root.

This is easiest with:

You can then run the test suite by navigating to:

http://0.0.0.0:3000/test/

At this point you can modify /src/htmx.js to add features, and then add tests in the appropriate area under /test.

  • /test/index.html - the root test page from which all other tests are included
  • /test/attributes - attribute specific tests
  • /test/core - core functionality tests
  • /test/core/regressions.js - regression tests
  • /test/ext - extension tests
  • /test/manual - manual tests that cannot be automated

htmx uses the mocha testing framework, the chai assertion framework and sinon to mock out AJAX requests. They are all OK.

javascript fatigue:
longing for a hypertext
already in hand

联系我们 contact @ memedata.com