The URL for the dynamic import in Workbox is loading incorrectly

For my laravel/vuejs application, I am utilizing workbox and babel dynamic imports. Additionally, I am making use of the laravel-mix and laravel-mix-workbox plugin to compile and generate service worker via generateSW().

The assets load correctly on the root URL https://myapp.test/ based on conditions set in vue-router. For example: https://myapp.test/assets/js/chunk1.js. When navigating to child pages like https://myapp.test/post/post1, the relevant chunks for that page also load successfully. Everything seems to be working fine so far!

However, when I directly visit a post page (https://myapp.test/post/post1), the dynamic asset URLs get appended to the latest slash, resulting in https://myapp.test/post/assets/js/chunk1.js and causing them to fail to load. It's as if the root URL is being set as the first page we visited.

I attempted to add output.path and output.publicPath in the webpack config, but they did not resolve the issue.

Some related packages I am using:

"devDependencies" {
   "workbox-webpack-plugin": "^6.0.2",
   "babel-plugin-syntax-dynamic-import": "^6.18.0",
   "laravel-mix": "^5.0.9",
   "laravel-mix-workbox": "^0.1.4",
}

Here is my generateSW configuration:

mix.generateSW({
    mode: 'development',
    runtimeCaching: [
        {
            urlPattern: /\.(?:jpg|jpeg|svg|png|json)$/,
            handler: 'CacheFirst',
        },
        {
            urlPattern: /api($|\/?.*)/,
            handler: 'NetworkFirst'
        }
    ],
    exclude: [
        /(backend.css|backend.js)/
    ],
    include: [
        /\.(?:ttf|js|css|glb)$/,
        /(\/font.png)/
    ],
    skipWaiting: true,
});

Thank you for taking the time to read this.

Answer №1

After hours of troubleshooting, I was able to resolve the issue by including a <base> tag in the html <head>. It turns out that workbox relies on this tag to determine the base URL.

<base href="https:://myapp.test/">

In my case using Laravel:

<base href="{{config('app.url')}}">

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

Unlocking the power of NextAuth by incorporating wild card or custom domains into the signin logic

My NextJS application is a multi-tenant SaaS application where each customer can choose to use a subdomain on our site or map their custom domain via CNAME. This setup allows customers to enable their employees to log in on either the subdomain site or cu ...

Can an iterated element be used as an object key in the data property within a "v-for" loop?

My situation is similar to this: v-for="i in 10" new Vue({ el: '#app', data: { howManyRow: null, date: { 1: Sat Dec 28 2019 00:00:00 GMT+1100 (Australian Eastern Daylight Time), 2: Sat Dec 28 2019 00:00:00 GMT ...

Error: Attempting to access the first element of a null property is not allowed

Currently, I am working on a NodeJS Project that utilizes Sails.js as the framework. The goal is to implement a permissions system where each group's permissions are set using Check Boxes within a form powered by AngularJS. However, upon clicking th ...

What steps do I need to take to modify the MUI Badge component and insert custom text inside?

Is there a way to replace the number with a label next to a new row added to my table using MUI Badge? For example, instead of displaying a number like 4, I want it to show the word "New" as shown in this image: enter image description here This is the co ...

Convert a date from the format of YYYY-MM-DD HH:MM:SS to MM-DD-YYYY using Javascript

Looking to transform YYYY-MM-DD HH:MM:SS into MM-DD-YYYY For instance: Given a date string in the format: 2013-06-15 03:00:00 The goal is to convert this string to 06-15-2013 using JavaScript. Is there a library available for this task, or should I rely ...

Is there a way for me to monitor a prop using the composition api?

Is there a way to trigger a function upon prop update? The parent container structure is as follows: <div> <Maintable :type="typeRef" :country="countryRef" /> </div> And here's the child container code: e ...

Returning a value with an `any` type without proper validation.eslint@typescript-eslint/no-unsafe-return

I am currently working on a project using Vue and TypeScript, and I am encountering an issue with returning a function while attempting to validate my form. Below are the errors I am facing: Element implicitly has an 'any' type because expression ...

Eliminate any duplicate items from the array containing objects

I've been struggling with this issue for a week now, hopefully someone here can help me out... The application I'm working on was created using Laravel with Vue for the frontend. Essentially, I have an array of objects that need to be sent to t ...

Having trouble with the search function in my array, as it is consistently returning false instead of the expected result

Aim: I am working on creating a basic search bar that allows users to input a zip code and matches it with zip codes stored in an array. The objective is to develop a function that can determine whether the entered zip code exists in the array or not, and ...

Having difficulty resolving sub-modules using webpack

Currently, I am trying to set up the @microsoft/signalr npm package with webpack by importing the module using import * as signalR from '@microsoft/signalr'. However, I encountered an error message indicating that webpack is unable to resolve the ...

How can I effectively develop a versatile user interface for a website using Ruby on Rails that is compatible with all

Currently, I am in the midst of developing a web application using Ruby on Rails. Occasionally, I encounter challenges with cross-browser compatibility when it comes to CSS and Javascript. Are there any strategies you recommend to reduce these issues dur ...

Search the database to retrieve a specific value from a multi-dimensional array

My database is structured as shown in the image below: https://i.sstatic.net/Flne8.png I am attempting to retrieve tasks assigned to a specific user named "Ricardo Meireles" using the code snippet below: const getTasksByEmployee = async () => { se ...

Inertia with Laravel appears to be triggering Vue components to load twice

After creating a Laravel project with Inertia and Vue, I encountered an issue where the code inside my Vue components is executed twice. To demonstrate this problem, I have created a Test.vue, containing the following code: <template> <div> ...

Adjusting the array of buttons with various functions within the Header component

I am looking to create a customizable Header component with different sets of buttons that trigger various functions. For example, on the home page, the buttons could be "visit about page" and "trigger vuex action A", while on the about page they could be ...

The output is displaying an Object instead of a numerical value in JSON

When I try running the URL in Chrome, the output I receive is: { "Train_score": { "0": 0.9892473118 }, "Test_score": { "0": 0.9831932773 } } However, when I attempt to use the following code to retrieve the JSON data using Javascript, co ...

Instructions for rearranging the configuration of a 2D array?

A 2-dimensional array is created from a string called matrix: 131 673 234 103 018 201 096 342 965 150 630 803 746 422 111 537 699 497 121 956 805 732 524 037 331 After parsing, it becomes an array of arrays like this: [ [131, 673, 234, 103, 018], [2 ...

Express.js does not recognize the req.query value

Incorporating Stripe Checkout functionality into a MERN application has been the focus of my recent project. Upon successful payment by a customer, they are directed to a checkout success URL where the CheckoutSuccess page is displayed. Additionally, Stri ...

"Encountering issues while upgrading Polymer project version from 0.5 to 1.0

I am in the process of upgrading my project from polymer .5 to polymer 1.0. After installing the new version of the polymer library, iron element, and paper element, I encountered the following error: polymer-micro.html:63 Uncaught TypeError: prototype ...

Creating a repository of essential functions in AngularJSDiscover the steps to set up a

I am looking to create a set of reusable functions in AngularJS for CRUD operations that can be used across multiple entities in my project. I have already set up a factory using $resource for server communication, which looks like this: Model File: var ...

Extract data from a JSON file and refine an array

Currently, I am working with reactjs and have an array stored in a json file. My current task involves filtering this array using the selectYear function. However, when attempting to filter the data using date.filter, I encounter the following error: An ...