PHP SPA Single Page Application

Creating a PHP single page application (SPA).

Reasons for implementing your PHP application as a Single Page Application (SPA) using WebRocketX

While SPAs are often associated with a heavy weight client-side JavaScript frameworks (Angular, React, View, Svelte etc) combined with JSON services, it's still entirely possible to leverage the benefits of an SPA while rendering HTML server-side with our lightweight JavaScript SPA framework.

  • Storing More View And User Input State On The Browser - The combination of caching views and selectively refreshing parts of the page results in significantly more state being retained in the browser. Consequently, developers needn't make as many trips to the server to access this pre-existing state. This proves advantageous even for tasks as straightforward as form submission. When the server rejects submitted user input, the page with the form retains all its user input client-side, ensuring it is not lost. On the other hand, a rejected form in a full page refresh model loses all user input since the browser is in the process of displaying the next page, and the form page disappears. Thus, in the case of a full-page refresh, the input would need to be sent to the server and redisplayed, resulting in the entire form being re-rendered and the unsaved user input restored. Although the form parameters would be restored from the request, they wouldn't be retrieved from the database as the submission was invalid, preventing the data from reaching that stage. Neglecting user experience, one might display an error message and require users to re-enter everything. Contrast this with the behavior of a single page PHP application using micro-requests, the page remains intact, because we never left it, allowing for the straightforward display of an error message from the server as a floating modal dialog.

  • Advantages of Micro Requests in Services - Since only targeted parts of a page are fetched, the required data becomes more specific, reducing the necessary business logic in services. This simplifies retrieval from external applications such as databases and cloud services.

  • Advantages of Micro Requests in UI State Maintenance Refreshing just part of the page means an entire page doesn't have to be pulled every time we navigate. Only an HTML snippet or JSON object needs to be fetched from the server. This simplifies the UI developer's task, as they don't have to include the header, menu, and footer templates in every page or concern themselves with the state of other data outside the refresh area. Even uncommitted user input remains secure as long as it's outside the refreshed area, alleviating much of the UI development burden.

  • Structured Error Handling Server-side errors and session timeouts can be troublesome when a developer anticipates layout or data from an asynchronous callback. WebRocketX standardizes error handling and session timeout behavior to prevent unpredictable outcomes. All responses undergo screening before the callback is sent to the developer, eliminating an unpredictability. Additionally, hooks are provided to allow developers to define custom behavior for callback failures.

  • User Interaction Control Problems like users pressing a button twice are eliminated by WebRocketX, which overlays the UI with a transparent layer during server round trips to prevent user interaction. Furthermore, the framework displays a user-friendly hourglass cursor to indicate a request is being made.

  • Structured View Navigation Previously rendered views can be accessed using their identifiers. Capsule attribute options allow the developer to mark views declaratively to be cached, or to force a reload to prevent staleness.

Contact Us

 If you have questions about WebRocketX, please feel free to contact us at: