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

Tips for delaying a StateChangeStart event until the completion of a ui-router resolve operation

In my angular application, I have implemented authorization logic and ui-router to restrict unauthorized users from accessing certain states/views. The standard approach I follow is to listen for a stateChange event that triggers the authorization logic. E ...

Convert the Date FR and Date US formats to ISO date format

There is a function in my code that accepts dates in different formats. It can handle two formats: 2022-06-04 or 04/06/2022 I want all dates to be in the format: 2022-06-04 For instance: public getMaxduration(data: object[]): number { data.forEach((l ...

In my React application, I have integrated p5 sketches that constantly loop and repeat

Currently facing a challenge integrating p5 sketches into my React App. I've tried adjusting the z Index of the toolbar to place the p5 elements underneath, but they end up repeating instead. Check out the repository here (sketches can be found in the ...

Display the source code of an HTML element when clicked

Is there a way to show the source code of an element on a webpage in a text box when that specific element is clicked? I am wondering if it is feasible to retrieve the source code of an element upon clicking (utilizing the onClick property), and subseque ...

A guide to creating an npm library featuring TSX components and utilizing CSS modules

I am currently working on developing an npm module that consists of React components and functions which can be easily imported into a NextJS project. However, I have encountered a few challenges in the process. The main issue is that all JavaScript files ...

Display information from an array in a dynamic dropdown menu using jQuery-AJAX within the Laravel 4 framework

I'm currently facing some challenges while trying to create a dynamic select box using jQuery. The main issue lies in implementing a 'route' that accesses my database to retrieve data for the new select box: Route::get('contenidos/comb ...

What is the best way to add multiple elements to an array simultaneously?

I am facing an issue with my array arrayPath. I am pushing multiple values into it, but there are duplicates in the data. When the value of singleFile.originalFilename is a duplicate, I do not want to push that duplicate value into arrayPath. How can I ach ...

"Is there a way to effectively showcase an error message for AJAX requests in a Rails

I'm having trouble getting an error message to display in Ajax using Rails. I've tried multiple approaches, but nothing seems to work. Below is the form where I want to show my errors: #flash-error.flash-error{:style => "display: none"} #fla ...

Is it possible for issues to arise when serving a web app using the "Globals" module in the Mean Stack?

Looking to transfer a variable (a constructed filename) from one file to another within an API can be quite challenging. One solution that comes to mind is utilizing globals, but with my current code structure, it seems like the only viable option. To addr ...

Guide on testing a function with a dependency in Angular through unit testing

Attempting to dive into unit testing, I have grasped some of the basics. However, my current challenge lies in testing a method within my code. This particular method involves calling a function from oidc-client.js that handles user sign-ins. My spec fi ...

Attempting to retrieve assets from an incorrect directory in a rush

Within my express project, I have encountered an issue when rendering the product route with a specific id. It seems that the assets are attempting to load from /products in the public folder (even though this directory does not exist). However, when I ren ...

Unable to display content when the button is triggered

I am facing an issue with hiding a div (class="login-form") and displaying it only after clicking the Login button on my HTML page using jQuery. However, despite clicking the button, the login form does not appear. Can anyone help me understand why this ha ...

The function for executing the specific command is not recognized and is resulting in a TypeError: client.commands

I'm having an issue with the code below and need a solution. Please help. Error : TypeError: client.commands.get(…).execute is not a function I am encountering difficulty with this specific command in my code: client.command ...

I'm a bit uncertain about the best placement for my progress bar component during the API call

Trying to grasp material ui I managed to implement the progress bar. Struggling with loading it until my data is fully loaded. Uncertain about where to place my progress bar component. Could you guide me on how to resolve this issue during API calls, so I ...

Receiving a notification when attempting to log in with incorrect credentials

I am currently working on an Angular login page implementation using a username and password setup. When the user enters incorrect credentials, I want to display an alert message indicating the same. Here is the HTML code snippet for the form: <form [f ...

Create an animation effect where a div increases in height, causing the divs beneath it to shift downward in a

My aim is to create columns of divs where the user can click on a div to see more content as the height expands. I've managed to set this up, but it seems there's an issue with the document flow. When I click on a div in the first column, the div ...

Utilizing Vuex, is it possible to filter an array by incorporating another array in a Javascript view?

When using VueX, I am attempting to filter my "ListJobs" array based on the currentTag. Essentially, I want to return elements that match any of the values in the currentTag array with the rows role, level, languages, and tools. state: [ listJobs: ...

Removing a value from a JavaScript object

Looking to delete a specific value from an object with multiple values? This is how my object is structured: { 'how can i change my password?': [ 'how can I change my password?', 'how may I change my password?', ...

AngularJS Constants in TypeScript using CommonJS modules

Let's talk about a scenario where I need to select a filter object to build. The filters are stored in an array: app.constant("filters", () => <IFilterList>[ (value, label) => <IFilterObject>{ value: value, label: label } ]); i ...

Mastering Vue.js: Leveraging v-model within a v-for loop and implementing watchers

After retrieving a list of debits and credits from a server using the fetch function, I store them in my Vue application: const myApp = Vue.createApp({ data(){ return{ debits:[], credits:[], //cut } }, me ...