Jump to content
[MUST READ] Forum Rules ×

creating PWA: it works in local but not in web


Herchi

Recommended Posts

my-pwa:

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>index.html</title>
  <link rel="manifest" href="manifest.json">
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('load', () => {
        navigator.serviceWorker.register('sw.js')
          .then(reg => console.log('Service worker registered!', reg))
          .catch(err => console.error('Error registering service worker', err));
      });
    }
  </script>
</head>
<body>
  <h1>Welcome to my Progressive Web App!</h1>
  <p>This is a basic example of a PWA with a manifest and a service worker.</p>
</body>
</html>

 

manifest.json

{
    "name": "My PWA",
    "short_name": "My PWA",
    "start_url": "/",
    "display": "standalone",
    "icons": [
        {
            "src": "https://cdn-icons-png.flaticon.com/512/16/16410.png",
            "sizes": "192x192",
            "type": "image/png"
        },
        {
            "src": "https://cdn-icons-png.flaticon.com/512/16/16410.png",
            "sizes": "512x512",
            "type": "image/png"
        }
    ]
}

 

sw.js

self.addEventListener('install', event => {
    console.log('Service worker installed');
});

self.addEventListener('activate', event => {
    console.log('Service worker activated');
});

self.addEventListener('fetch', event => {
    console.log('Intercepting fetch request for:', event.request.url);
});

 

 

 

It s a simple PWA that it works in my XAMPP:

Spoiler

z3hJ3Q4.png

 

 

but in http://azucarados.byethost4.com/my-pwa/?i=1

Manifest: Line: 1, column: 1, Syntax error.

Spoiler

QSdy5gE.png

 

😣

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...