Tips for navigating the world of hybrid web applications that combine elements of both traditional multi-page applications and single-page

What are some best practices for developing a multi-page application using modern JavaScript frameworks?

Multi-page Application

In a multi-page application, we utilize multiple templates with "template syntax" to retrieve backend data and handle AJAX (if necessary), while advanced UX features are often managed by jQuery.

Single Page Application

In a single page application, backend data is fetched through AJAX requests and all routing and frontend logic is handled by JavaScript. Typically, JS frameworks like Angular or React are used, along with task runners/bundlers such as webpack or gulp.

Hybrid Application

The hybrid app seems to be the most popular choice nowadays. What is the typical workflow when working on such an app? I have been unable to find any tutorials or guides on this topic.

To be more specific, imagine a web app where each page needs to be compiled and can share certain resources. Each page has its own JS routing, like wizards or subcomponents, and data is loaded during both page load and via AJAX.

For example, my web app may consist of 3 pages:

  • Guest page - providing limited content to website users to encourage them to sign up
  • User page - offering full content to signed-up users, with additional resources beyond the guest content
  • Admin page - sharing only styles and the core functionality of the web app

Task Runners/Bundlers

In webpack, is there a way to define multiple entry and output points? Perhaps having multiple webpack/gulp configurations would make more sense. If I have numerous pages, do I need to create webpack/gulp configurations for each one, even if some could be identical? How should this build process be executed?

Shared Resources

If a browser already has a cached JS bundle with the same hash, such as bundle.a2k4jn2.js, within the same domain but different address, will it be loaded? How can this behavior be specified in tools like webpack or gulp? I've heard about the CommonsChunkPlugin, but I'm unsure about how to use it or if I'm heading in the right direction.

Templates

What if I want to load some backend data not via AJAX, but during the initial page load? While every templating engine allows us to include native code directly into HTML templates, situations where routing is managed by JS and template tags are not visible until after initial loading exist. Sometimes, conflicts can arise when server-side and client-side template engines use the same special tag, like Blade and Angular.

Directory Structure

In a hybrid app, the frontend and backend are closely linked. Sharing JS in a hybrid app could result in complex imports (in ES6 or HTML script tags). How can complexity be kept at bay?

Deployment

When it comes to deploying an application, Java makes it simple by specifying directories (compiled pages) in build tools like Maven or Gradle, which are then copied to a JAR/WAR file. However, PHP source code is not compiled. Is there a sensible solution to keep the "JS source" separate from production, other than writing a custom batch/bash script?

Summary

I've referenced specific technologies and frameworks here, but my focus is on general approaches to managing a web app rather than simply how-to instructions for particular tools. That being said, I welcome any code examples that could aid in understanding.

Answer №1

There is a wealth of information within this inquiry, particularly regarding setting up multiple entry points in webpack.

Learn more about defining entry points in webpack here

To streamline data loading processes between front-end and back-end, consider developing an isomorphic JavaScript application utilizing Node.js on the backend. Avoid duplicating efforts by writing code in multiple languages, as it can lead to inefficiencies – speaking from past experience.

Regarding shared resources, WebPack’s bundle splitting feature fits perfectly with the requirements outlined in this question.

Explore WebPack's bundle splitting functionality for optimizing shared resources

Answer №2

While I may not grasp the question completely, single-spa (yes, it's a bit redundant) serves as a useful tool for merging multiple apps, even if they are built on different frameworks, into a unified single page application. You can find more information in the documentation:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it a breach of separation of concerns to validate using ng-pattern?

I have a requirement in Singapore to validate contact numbers entered by users. The number must start with 6, 8, or 9 and should have a total of 8 digits. I am currently utilizing ng-pattern on an input field with a regex solution, but I am concerned abo ...

Solving the problem of Axis label alignment in Three.js grid and techniques for visualizing x, y, z data on

I have been tasked with plotting well deviation surveys on a 3D grid. After referencing several articles online, I successfully created a 3D grid of the required size. However, I am currently struggling with positioning the labels for the x, y, and z axis ...

How can I prevent div duplication when working with ui-router?

I created a basic demonstration to get familiar with ui router. Unfortunately, I encountered an issue of duplicated views when utilizing ui router. Below is the snippet of the stateProvider section: app.config(function($stateProvider,$urlRouterProvider) ...

tips on customizing buttons within form groups

I have set up two separate form-groups: My goal is to click on each button within each group and toggle its style from grey to green, and vice versa. However, when I click on a button, all buttons within the group turn grey except for the one that was cli ...

Lazy loading a React grid gallery as you scroll

Currently, I am utilizing React grid gallery to showcase images from this repository: https://github.com/benhowell/react-grid-gallery. However, I am encountering an issue with lazy loading when the user scrolls on the page. <Gallery images={this ...

Forwarding refs in React FC allows you to easily pass down

I have encountered an issue with references - I am trying to reference a function component and pass props to it. Currently, I have my Parent component and Child Component set up. In the parent component, I need to use a ref to access my child component. S ...

What is the best way to transfer information between two separate Javascript controller files?

My current situation is a bit complex, but I believe there must be a straightforward solution. I have two Javascript controller files: one named rootPageClient.js and another called findPollClient.js. Additionally, there's a file called ajax-function ...

What is the reason this JavaScript code functions properly within a <script> tag but not when placed in a separate .js

After researching various image sliders online, I came across this specific one. It worked perfectly fine when I included the JavaScript directly in a script tag within the HTML file. However, as soon as I tried to link it via a .js file, the slider stoppe ...

Moving a div horizontally while clicking and holding on a control button with a smooth animation effect

I am currently working on a new feature inspired by a previous question I found on Stack Overflow. My goal is to make the scrolling start slowly and then gradually speed up. However, I am facing an issue with using easing in the animate function as it get ...

Struggling with routing in Node.js while working on REST API development via HTTP

I am facing an issue while trying to complete a MEAN project. The client side is already done, but I am having trouble with the server side when attempting to make a new insertion (which is carried out using HTTP Post). Below, I will demonstrate how I hav ...

Is it possible for the data submitted in a POST request to be converted into URL parameters?

Our technology stack: Frontend built with Vue.js and utilizing the vuetify component library Custom Python middleware REST API using Flask + Tornado External Matomo setup connected to the frontend via the vue-matomo plugin system (https://github.com/Amaz ...

"Exploring the depths of sub directories in Node.js: A guide to printing

Once again, I find myself stuck with node.js and in need of your assistance. I am attempting to write a script for the command line interface that will search for all subdirectories under the current directory (process.cwd), and only print out those that ...

Upgrading the entire document's content using jQuery

I am dealing with an ajax response that provides the complete HTML structure of a webpage, as shown below: <!DOCTYPE> <html> <head> <!-- head content --> </head> <body> <!-- body content --> </b ...

The directives applied within ng-include are not functioning correctly

Below is a custom directive I have implemented. var fancySelectDirective = pluginDirecitvesModule.directive("custom-select",function(){ return { restrict: 'C', link: function (scope, element, attrs) { ...

The Datepicker and Tablesorter dilemma

Having a Datepicker and Tablesorter on the same View Page presents an issue for me. When I remove the tablesorter, the datepicker functions properly. However, when I reintroduce the tablesorter, the datepicker stops working entirely. Below is the code sni ...

What could be improved in this Angular script?

angular.module('events.services', []) .factory('EventService', function($http, $cordovaSQLite) { return { fetchData: function() { return 'Data fetched successfully!'; } ...

An error will occur if you try to modify the state of a component from outside the component

Creating a modal component that triggers a bootstrap modal from any section of the application and then defines custom states for that component externally. It is functional, however, an error message consistently appears upon opening the modal, and I am u ...

Using DataTable with backend processing

Has anyone successfully implemented pagination in DataTable to dynamically generate the lengthMenu (Showing 1 to 10 of 57 entries) and only load data when the next page is clicked? I'm currently facing this challenge and would appreciate some guidance ...

The dropdown menu in Mantine is malfunctioning, even though I copied and pasted the exact code from

While following a tutorial, I encountered an issue with the Mantine Menu and Dropdown components. The tutorial creator did not wrap the React App inside the MantineProvider, which resulted in errors when trying to use the Dropdown component. Even after add ...

Steps to set up gapi-script authentication with next-auth in a Next.js application

I have encountered an issue while working on my open-source project that involves utilizing the Google Drive API. Can anyone guide me on how to set up gapi-script authentication using next-auth in a Next.js project? I have managed to implement authentica ...