Swap.js

Languages and libraries

javascript micro-framework

SHOW HN2023

127points
45comments
#494of 3,109 in 2023
Top 16%of 2023 by points

How HN took it

MixedNo clear lean

7 positive, 8 neutral or asking, 1 mixed, 4 critical, out of 20 comments about the project. Thread score +0.20.

Idea: 2 for, 3 againstExecution: 3 for, 0 againstDesign: 2 for, 0 againstPrivacy: 0 for, 1 against

The thread, comment by comment

Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.

positive neutral or mixed critical about another commenter or something else the maker

What HN said

What people liked

  • Tiny size and readable source with no build tools needed

    From 4 comments
    • > vanilla JS (no external tool needed: no bundler, no webpack, no TypeScript compiler, no minification needed...) Nice, I like that. I dread the modern way of having to jump…
      janwillemb on HN
    • I read through the swap.js file and there's a lot of things happening. I also like the fact that it has no dependencies and it's cool that it achieves so much with so little code.
      harha_ on HN
    • Wow. That is beautiful. So concise and yet easy to understand.
      victorbjorklund on HN
    • Impressive, especially considering the implementation size. Just by looking at swap.js file, I could not actually believe it really works but it clearly gets the job done.
      garganzol on HN
  • Similar to HTMX and pjax, a welcome return of ajax-style navigation

    From 3 comments
    • I'm getting a bit of deja vu from this recebt rediscovery of ajax but i really like it. Back when js was obscure and jQuery became ubiquitous, that practice was a go to and sites…
      krsdcbl on HN
    • I like it, but it feels funny to have this discussion without acknowledging this is really similar to pjax/turbolinks. Ok, now I'm feeling better; carry on!
      wryun on HN
    • This is much better than htmx. I like the focus on just swapping content
      ulrischa on HN

Objections

  • Only supports GET links, not form POSTs, so limited for real sites

    From 2 comments
    • Lib is EXTREMELY minimal. Only GET requests with anchor tags. That you can’t POST forms or send metadata make it mostly useless for anything but the most basic website. I guess…
      devmunchies on HN
    • It's not about the POSTing. Its how you handle the response. The paradigm of this library is that you replace segments of the page with the response, which it doesn't support for…
      devmunchies on HN
  • Replacing document.body can break browser extensions and scripts

    From 1 comment
    • Link handling needs to check keyboard modifier state, so that you don’t intercept things like Ctrl+click. You can also work with just one event handler rather than many. Here’s…
      chrismorgan on HN
  • Injecting HTML via innerHTML raises XSS concerns

    From 2 comments
    • Ah the good old element.innerHTML = xss_vector_here
      dvh on HN
    • Link handling needs to check keyboard modifier state, so that you don’t intercept things like Ctrl+click. You can also work with just one event handler rather than many. Here’s…
      chrismorgan on HN

Requests

  • Document accessibility impact for screen readers

    From 1 comment
    • Feature request: documentation describing the accessibility impact this will have. Any time I'm considering a library like this my number one question is always the impact it…
      simonw on HN
  • Add polling for updates at intervals

    From 1 comment
    • Have you thought about adding polling functionality, so that a given element can check with the server for updates at a set interval?
      replwoacause on HN

Questions

  • How does it compare to HTMX and Unpoly

    From 2 comments
    • How would you compare yourself to HTMX and Unpoly? I'm keenly interesting in this space for sure and love that you're working on another!
      canadiantim on HN
    • Why is it much better?
      replwoacause on HN
  • Should custom attributes use a data- prefix

    From 2 comments
    • Someone who used jQuery.load a lot back in the day, it's nice to see this trend coming back. Only thing that stands out to me is using custom properties without data prefix, e.g.…
      Ciantic on HN
    • I believe doing this is already quite common and there's no real drawback. As far as I know the main advantage of the data- prefix is that there's a guarantee that no official…
      solarkraft on HN

Alternatives named

  • HTMX

    From 2 comments
    • I’m bought in to this approach after using Hotwire, but I’m concerned that all the competing implementations are going to undermine adoption. Maybe we should all just use htmx…
      dyeje on HN
    • How would you compare yourself to HTMX and Unpoly? I'm keenly interesting in this space for sure and love that you're working on another!
      canadiantim on HN
  • Unpoly

    From 1 comment
    • How would you compare yourself to HTMX and Unpoly? I'm keenly interesting in this space for sure and love that you're working on another!
      canadiantim on HN
  • pjax and Turbolinks

    From 1 comment
    • I like it, but it feels funny to have this discussion without acknowledging this is really similar to pjax/turbolinks. Ok, now I'm feeling better; carry on!
      wryun on HN
  • Hotwire

    From 1 comment
    • I’m bought in to this approach after using Hotwire, but I’m concerned that all the competing implementations are going to undermine adoption. Maybe we should all just use htmx…
      dyeje on HN

Category, keywords, summaries and labels on this page were made by AI (Thread Reader v2) and not checked by hand. Each point links to the comments it came from.

Add a badge to your READMEShown on HackerShow
[![Shown on HackerShow](https://hackershow.org/badge.svg)](https://hackershow.org/show/35991783)