Over the weekend, I converted a suite of custom web apps I maintain for my family from using a JS-rendered UI to my preferred PHP Islands Architecture approach. All of the initial HTML is rendered in advanced. Today, I wanted to show you how I turn static HTML into dynamic web apps using a mix of old-school server techniques and modern HTML Web Components. Let's dig in! Static HTML vs. PHP Islands ArchitectureWith this approach, all of the initial HTML is rendered in advanced. A lot of it is pre-rendered static HTML. Some of it—the stuff specific to the current user—is dynamically rendered on the server with PHP.
Wherever there's a user interaction that updates something on the backend, I user
As a baseline experience, submitting the form triggers a full page reload. It sends data to the server, which does some stuff, then redirects the user back to the page they just came from. The page is reloaded, and they see there updates rendered into the new HTML. But I also like ajaxy interactions, which can maintain a user's position on the page and show "in progress" status updates. To support this, I wrap my
When the user submits the form, this Web Component stops it from reloading the page, and makes a When it gets back a response, it renders it into the UI. It also prevents multiple submissions while one is in progress, clears the form after its successfully submitted, and emits a custom event. (I'll talk more about how this works in another article. For now, you can find that Web Component in my membership toolkit). But this creates a problem… How do you update HTML that depends on that form's data?In JavaScript framework land, you use hydration: HTML is rendered on the server, and then a whole bunch of JavaScript to make it a state-based UI component is loaded to take over. I did not want to do that. So, I created a Web Component that listens for form events and updates the HTML dynamically…
Whenever the form event fires, if it was fired on the The rest of the page remains untouched. And tomorrow, I'll show you how that all works! Like this? A Go Make Things membership is the best way to support my work and help me create more free content. Cheers, Want to share this with others or read it later? View it in a browser. |
Beranda » Tanpa Label » [Go Make Things] Dynamic content on a static HTML page using Web Components and PHP
0 Komentar untuk "[Go Make Things] Dynamic content on a static HTML page using Web Components and PHP"