検索

HTMX is the successor to intercooler.js, as is used to extend HTML with HTTP commands without needing to write an API. Now, I know in the beginning I said I was removing abstraction layers, however I'm more of systems/tooling programmer, so I still need some abstractions until I have a grasp of what is actually happening underneath.

Basic Concept

HTMX deploys AJAX commands to modify an element. This is similar to how ReactJs works. ReactJs allows for updating content, and HTMX is fulfilling that for HTML.

Import HTMX

A simple one liner is added to ./internal/views/layout.templ

element.

This was already included in the repo, however it has been updated to verify the script.

Using HTMX

HTMX comes with all of your favorite keywords appended with hx-.

# General format is hx-[verb]
hx-get        # HTTP GET
hx-post       # HTTP POST
hx-put        # HTTP PUT
hx-patch      # HTTP PATCH
hx-delete     # HTTP DELETE
hx-swap       # update content of an element
hx-target     # specify element to affect
hx-trigger    # action that executes function

There are more, however these are the main ones used in this project.

For a simple test, in ./internal/views/components/logo.templ, inside of the opening HTMX を GO に追加する tag, we're going to add hx-get="/" and hx-trigger="click".

Open your terminal and run:

templ generate
go run ./cmd/server/main.go

Now go to your browser and go to localhost:[YOUR PORT]/. Click on Gopher, and you should see... well, it happened so fast, you probably didn't notice. That's okay. Open the developer tools, and go to the inspector tab. Click the Gopher again. You should notice the update in the HTML in the inspector tab.

HX-SWAP

This is the bread and butter of HTMX. This is what gives us the responsive UI/UX we're looking for. Now, hx-swap, while simple in name, needs careful consideration on it's location. By this, I mean, do not put it where it will interfere with other elements.
Example:

<div> // container
    <button hx-delete="[endpoint]" hx-target="nearest [element]" hx-swap="outerHTML" hx-get="[endpoint]"> // actor
    </button> // end actor
</div>// end-container

Placing all of the control on the button, will cause everything to be erased and prevent a button, for updating, being displayed. However, if we move some of the work to the container:

<div hx-get="[endpoint]" hx-target="this"> // container
    <li>
        <button hx-delete="[endpoint]" hx-target="nearest [element]" hx-swap="outerHTML"> // actor
        </button> // end actor
    </li>
</div>// end-container

Now, when we click the button, only the data INSIDE of the container is changed, except now a button exists for further editing.

Addendum

I'm stopping here for two (2) reasons.
First, you can use htmx and customize your site with it as it is. Second, we can return html code with a http.Reponse. By extension, we can pass templ components as well. Do you see where this is going?

Coming Soon

An entire restructure and moving functionality into go handlerFunc()s.

Adding HTMX to GO

以上がHTMX を GO に追加するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
パフォーマンスレース:ゴラン対cパフォーマンスレース:ゴラン対cApr 16, 2025 am 12:07 AM

GolangとCにはそれぞれパフォーマンス競争において独自の利点があります。1)Golangは、高い並行性と迅速な発展に適しており、2)Cはより高いパフォーマンスと微細な制御を提供します。選択は、プロジェクトの要件とチームテクノロジースタックに基づいている必要があります。

Golang vs. C:コードの例とパフォーマンス分析Golang vs. C:コードの例とパフォーマンス分析Apr 15, 2025 am 12:03 AM

Golangは迅速な発展と同時プログラミングに適していますが、Cは極端なパフォーマンスと基礎となる制御を必要とするプロジェクトにより適しています。 1)Golangの並行性モデルは、GoroutineとChannelを介した同時性プログラミングを簡素化します。 2)Cのテンプレートプログラミングは、一般的なコードとパフォーマンスの最適化を提供します。 3)Golangのごみ収集は便利ですが、パフォーマンスに影響を与える可能性があります。 Cのメモリ管理は複雑ですが、コントロールは問題ありません。

Golangの影響:速度、効率、シンプルさGolangの影響:速度、効率、シンプルさApr 14, 2025 am 12:11 AM

speed、効率、およびシンプル性をspeedsped.1)speed:gocompilesquilesquicklyandrunseffictient、理想的なlargeprojects.2)効率:等系dribribraryreducesexexternaldedenciess、開発効果を高める3)シンプルさ:

CとGolang:パフォーマンスが重要な場合CとGolang:パフォーマンスが重要な場合Apr 13, 2025 am 12:11 AM

Cは、ハードウェアリソースと高性能の最適化が必要なシナリオにより適していますが、Golangは迅速な開発と高い並行性処理が必要なシナリオにより適しています。 1.Cの利点は、ハードウェア特性と高い最適化機能に近いものにあります。これは、ゲーム開発などの高性能ニーズに適しています。 2.Golangの利点は、その簡潔な構文と自然な並行性サポートにあり、これは高い並行性サービス開発に適しています。

Golang in Action:実際の例とアプリケーションGolang in Action:実際の例とアプリケーションApr 12, 2025 am 12:11 AM

Golangは実際のアプリケーションに優れており、そのシンプルさ、効率性、並行性で知られています。 1)同時プログラミングはゴルチンとチャネルを通じて実装されます。2)柔軟なコードは、インターフェイスと多型を使用して記述されます。3)ネット/HTTPパッケージを使用したネットワークプログラミングを簡素化、4)効率的な同時クローラーを構築する、5)ツールと最高の実践を通じてデバッグと最適化。

Golang:Goプログラミング言語が説明しましたGolang:Goプログラミング言語が説明しましたApr 10, 2025 am 11:18 AM

GOのコア機能には、ガベージコレクション、静的リンク、並行性サポートが含まれます。 1. GO言語の並行性モデルは、GoroutineとChannelを通じて効率的な同時プログラミングを実現します。 2.インターフェイスと多型は、インターフェイスメソッドを介して実装されているため、異なるタイプを統一された方法で処理できます。 3.基本的な使用法は、関数定義と呼び出しの効率を示しています。 4。高度な使用法では、スライスは動的なサイズ変更の強力な機能を提供します。 5.人種条件などの一般的なエラーは、Getest Raceを通じて検出および解決できます。 6.パフォーマンス最適化Sync.Poolを通じてオブジェクトを再利用して、ゴミ収集圧力を軽減します。

Golangの目的:効率的でスケーラブルなシステムの構築Golangの目的:効率的でスケーラブルなシステムの構築Apr 09, 2025 pm 05:17 PM

GO言語は、効率的でスケーラブルなシステムの構築においてうまく機能します。その利点には次のものがあります。1。高性能:マシンコードにコンパイルされ、速度速度が速い。 2。同時プログラミング:ゴルチンとチャネルを介してマルチタスクを簡素化します。 3。シンプルさ:簡潔な構文、学習コストとメンテナンスコストの削減。 4。クロスプラットフォーム:クロスプラットフォームのコンパイル、簡単な展開をサポートします。

SQLソートのステートメントによる順序の結果がランダムに見えるのはなぜですか?SQLソートのステートメントによる順序の結果がランダムに見えるのはなぜですか?Apr 02, 2025 pm 05:24 PM

SQLクエリの結果の並べ替えについて混乱しています。 SQLを学習する過程で、しばしば混乱する問題に遭遇します。最近、著者は「Mick-SQL Basics」を読んでいます...

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター