How can I configure Stencil PWA to function without an internet connection?

I've been working on developing a Progressive Web App (PWA) that is functioning well online using the Stencil PWA template. However, I'm facing challenges in getting it to work offline.

stencil.config.ts

import { Config } from '@stencil/core';

// https://stenciljs.com/docs/config

export const config: Config = {
  globalScript: 'src/global/app.ts',
  globalStyle: 'src/global/app.css',
  taskQueue: 'async',
  outputTargets: [
    {
      type: 'www',
      serviceWorker: {
        globPatterns: [
          // Prefetch all local data
          '**/*.{js,css,json,html,ico,png}',
          // Prefetch all the api calls
          'https://www.revisedenglishversion.com/jsonrevexport.php?permission=yUp&autorun=1&what=*',
        ],
      },
    },
  ],
};

The project can be found here. Would appreciate any guidance on what might be incorrect with my implementation?

Update: To address the issue, I have started caching the retrieved data using @capacitor/store, eliminating the necessity to cache it within the app.

Answer №1

Upon conducting a rapid assessment on your repository.

It appears that the URL in globPatterns is causing the precache manifest to be completely removed from sw.js. The reason for this remains uncertain, but considering that you are storing API results in the file system (using IDB in PWA), there is no need for the service worker to cache these requests. Thus, you can safely remove it.

Subsequent to this amendment, the PWA functions offline without issues, except for one minor setback: SVG icons are not being cached. One simple solution would be to append ,svg to the initial glob pattern; however, this would cache every single ionicon, potentially leading to unnecessary bulkiness.

Alternatively, you could manually specify which icons should be cached:

serviceWorker: {
  globPatterns: [
    // Basic caching criteria?
    '**/*.{js,css,json,html,ico,png}',
    'build/svg/{arrow-back-outline,home-outline,close-circle}.svg',
  ],
},

Remember to keep this list updated whenever adding or removing new icons.

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

Making decisions about data types during compilation?

Given an instance of type A or B, I want to implement a unified function that accepts a parameter of type A or B and returns its wrapped argument. Here is an example: type A = { name: string }; type B = A[]; type DucktypedA = { // we don't care about ...

Selecting an object dynamically to add a new property in JavaScript

I am faced with a scenario where I have two objects and I need to add new properties to them. The challenge is that I want to be able to choose which object to work with first before adding the new properties. Here's the proposed logic : let customiz ...

Rearrange the parent object's structure based on the data and length of the child array

Is it possible to restructure parent data based on the child array data and its length? Should I stick with an array structure or consider changing the object array from the backend? No IDs are present in the child arrays. This is what has been accomplis ...

Encountering an error when trying to set data in a Firestore document with a customized JavaScript object: "Invalid data provided for function DocumentReference.set()"

For my initial project, I need help in identifying where the issue lies. Firstly, I have a function that adds data to Firebase: addpost() { let newposts = new Posts( this.addForm.value ) this.postsservice.addPosts(newposts); } Ne ...

Accessing the constants and state of child components within a parent component in React

I've created a MUI TAB component that looks like this <Box sx={{ width: "100%" }}> <Box sx={{ borderBottom: 1, borderColor: "divider" }}> <Tabs value={value} onChange={handleChange} aria-label ...

You cannot use the "this" keyword outside of a class body

I am facing an issue with my function, can someone help me? Here is the code: function remove_multi_leg(): void { if (Number($("#search_no_legs").val()) < 2) { return; } const removeId: number = Number($(this).attr("data-number")); const ...

Issue with binding background images to DIV elements in Angular 4 CSS

Here is a template example: <div [style.background-image]="profileImage" ></div> In the TypeScript file: We declare private profileImage: any; and use DomSanitizer for security. Fetching photo from service: We set this.profileImage using b ...

Error message encountered in Next.js when trying to import 'SWRConfig' from 'swr': ClerkProvider Error. The import is not successful as 'SWRConfig' is not exported from 'swr

I recently started working on a new Next.js project and integrated Clerk into it. I set up the env.local and middleware.ts files before wrapping the HTML div with ClerkProvider. However, when attempting to run the project locally, I encountered the followi ...

What could be causing my vis.js network's node hover popups to not function properly?

I've encountered an issue where, despite adding the 'title' property to my node objects, the pop up window with the title content doesn't appear when I hover over a node. Here are the options I've chosen and how I've set up m ...

How to access a static TypeScript variable in Node.js across different files

I encountered a situation like this while working on a node.js project: code-example.ts export class CodeExample { private static example: string = 'hello'; public static initialize() { CodeExample.example = 'modified'; } ...

Managing a scenario with a union type where the value can be retrieved from one of two different functions

There are two similar methods that I want to refactor to eliminate redundant code. The first function returns a single element, while the second function returns multiple elements: //returns a single element const getByDataTest = ( container: HTMLElement ...

What could be the reason for receiving a TS message stating "Property 'value' may not exist on type 'boolean'. Did you intend to use 'valueOf'?" while updating state using RTK in React?

When attempting to create a slice using Redux Toolkit within the Visual Studio Code editor, I encounter a TypeScript warning that states "Property 'value' may not exist on type 'boolean'. Did you mean 'valueOf'?" This occurs w ...

Ag-grid with Angular 2 allows users to easily edit entire columns with just a few

I need help modifying a column in my ag-grid. My ag-grid currently looks like this: grid image I want to update all values in the column Etat to be arrêté, but I'm struggling to make it work. This is the code I've been trying: private gridO ...

What are the best methods for testing a function containing multiple conditional statements?

I have a complex function that I want to showcase here, it's quite simple but for some reason, I'm struggling with writing unit tests for it. I don't need the exact unit test implementation, just a general approach or tips on how to handle i ...

Is conditional compilation possible with ifdef-loader in combination with Angular 13 and Webpack?

My application built with Ionic heavily relies on conditional compilation, where I need to include or exclude code blocks based on specific config values, similar to the functionality of m4. Previously, I successfully utilized https://github.com/nippur72/ ...

Determine data type using the generic type of a related property in Typescript

I am seeking a method to specify the type of a property based on the generic type of another property within the same context. For instance, consider the following: type Person = { id: number; name: string; } type Select<Value=unknown> = (props ...

Apply ViewEncapsulation.None to all components

I find it frustrating how Angular automatically adds a "_ngcontent-*" in the elements of the HTML page. Since I don't really use that feature, I typically remove it by including "encapsulation: ViewEncapsulation.None" in my component. However, with nu ...

Tips for removing a row from a DataGrid column with the click of a button

I am facing a challenge with my data table that contains users. I am trying to implement a delete button for each row, but it seems like the traditional React approach may not work in this situation. Currently, I am utilizing the DataGrid component in the ...

Even after making changes within my Angular and Firebase subscription, my variable remains unchanged

In an attempt to secure my Angular application's routes, I decided to create a canActivate method that would check the user's status. My backend is based on Firebase, and user authentication, login, and sign up functionalities are all handled thr ...

What is the proper way to specify a generic type as a parameter in TypeScript?

I have devised a basic Form class using TypeScript: class Form<FormData> { protected data: FormData; constructor(data: FormData) { this.data = data; } } To ensure the form receives specific data upon instantiation, I included a ...