HACKER Q&A
📣 getrekt

Architecture for building interactive server rendered (MVC) web apps?


For instance, clicking a button brings up a modal with content that is generated server side.

I have done this via the server generating JavaScript that is eval'd client side. If JavaScript is disabled, the modal is opened on a new page instead.

What are some good patterns to enable this, while also having a safe fallback for when JavaScript is disabled?


  👤 stephenr Accepted Answer ✓
Have regular forms with action attributes, and regular links (potentially styled as buttons if it makes sense). Add a little JavaScript to make xhr (or fetch if you prefer) requests in place of the default behaviour.

A couple of data-* attributes can help control the specific behaviour of the JavaScript meaning you probably don’t need inline/page specific is code for every instance.

This isn’t a new approach, we were doing this back when IE6 was the “mainstream” browser.