πŸ“± Progressive Web Apps (PWA) & Offline Strategy in Oracle APEX

πŸ“± Progressive Web Apps (PWA) & Offline Strategy in Oracle APEX

πŸ”Ή About

Oracle APEX makes it incredibly easy to convert applications into Progressive Web Apps (PWA). But the real challenge begins when users expect the application to continue working even without internet connectivity.

In this blog, we’ll explore how to build a true offline-capable Oracle APEX application using:

βœ” Progressive Web Apps (PWA)
βœ” Service Workers
βœ” Browser Local Storage
βœ” Offline Data Synchronization
βœ” Custom Offline Page Design

This approach is especially useful for:

  • Field workers
  • Sales teams
  • Survey applications
  • Warehouse management systems
  • Remote inspection apps

πŸ› οΈ Tools and Technologies

  • Oracle APEX
  • JavaScript
  • Browser Local Storage
  • Service Workers
  • Oracle Database
  • PWA Manifest

πŸš€ What is a Progressive Web App (PWA)?

A Progressive Web App is a web application that behaves like a native mobile app.

With PWA, users can:

βœ… Install the app on mobile/desktop
βœ… Access the app fullscreen
βœ… Use caching for faster performance
βœ… Work offline (partially/full)

Oracle APEX provides built-in support for enabling PWA functionality.


πŸ”₯ The Real Challenge: Offline Capability

Enabling PWA is easy.

The difficult part is:

πŸ‘‰ What happens when internet connectivity drops?

Normally:

❌ Form submissions fail
❌ Data gets lost
❌ Users cannot continue work

For field workers, this becomes a major business problem.


🎯 Goal of This Strategy

We want users to:

βœ” Continue entering data offline
βœ” Save data locally in browser storage
βœ” Automatically sync to Oracle DB when internet returns


πŸ“Œ Step 1: Enable PWA in Oracle APEX

Go to:

Shared Components β†’ Progressive Web App

Enable:

  • βœ” Installable
  • βœ” Offline Support
  • βœ” Service Worker

πŸ“Œ Step 2: Configure PWA Manifest

The Manifest file controls how the application behaves as an installed app.

Example:

{
  "name": "Field Worker App",
  "short_name": "FieldApp",
  "start_url": "/ords/r/app",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#1976D2",
  "icons": [
    {
      "src": "icon-192.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ]
}

πŸ“Œ Step 3: Configure Service Worker

The Service Worker acts like a proxy between browser and server.

It enables:

βœ… Offline caching
βœ… Faster loading
βœ… Background sync

Example:

self.addEventListener('install', event => {
    event.waitUntil(
        caches.open('apex-cache').then(cache => {
            return cache.addAll([
                '/',
                '/offline.html'
            ]);
        })
    );
});

πŸ“Œ Step 4: Detect Online / Offline Status

Use JavaScript to detect internet connectivity.

window.addEventListener('offline', function() {
   console.log('Internet Disconnected');
});

window.addEventListener('online', function() {
   console.log('Internet Restored');
});

πŸ“Œ Step 5: Save Data in Browser Local Storage

When internet is unavailable, save data locally instead of losing it.


Example: Save Offline Data

function saveOfflineData(empname, salary) {

   let offlineData =
      JSON.parse(localStorage.getItem("emp_data")) || [];

   offlineData.push({
      empname: empname,
      salary: salary,
      sync_status: 'PENDING'
   });

   localStorage.setItem(
      "emp_data",
      JSON.stringify(offlineData)
   );

   console.log("Saved Offline");
}

πŸ“Œ Step 6: Synchronize Data When Internet Returns

Once connectivity returns:

βœ” Read local storage
βœ” Push data to Oracle DB
βœ” Clear synced records


Example Sync Logic

async function syncOfflineData() {

   let offlineData =
      JSON.parse(localStorage.getItem("emp_data")) || [];

   for (let row of offlineData) {

      await apex.server.process(
         "SAVE_EMP_DATA",
         {
            x01: row.empname,
            x02: row.salary
         }
      );

   }

   localStorage.removeItem("emp_data");

   console.log("Sync Completed");
}

πŸ“Œ Step 7: Trigger Automatic Sync

window.addEventListener('online', function() {
   syncOfflineData();
});

πŸ“Œ Step 8: Create AJAX Callback Process

BEGIN

   INSERT INTO emp_offline_data
   (
      emp_name,
      salary
   )
   VALUES
   (
      apex_application.g_x01,
      apex_application.g_x02
   );

END;

🎨 The Offline Page Explained

Oracle APEX also allows you to customize the Offline Page shown when users lose connectivity.

Before modifying the Offline Page, review the Oracle APEX documentation related to:

Progressive Web App (PWA) Messages Requiring Translation

You will find several message names starting with:

APEX.PWA.*

These messages control:

  • Offline page title
  • Offline page body
  • PWA error messages
  • Unsupported device messages

πŸ“Œ Important Offline Messages

πŸ”Ή Offline Page Title

APEX.PWA.OFFLINE.TITLE

πŸ”Ή Offline Page Body

APEX.PWA.OFFLINE.BODY

This is the most important message because it controls the actual HTML displayed on the Offline Page.


πŸ’‘ Why Use SVG?

It is recommended to use SVG graphics instead of PNG/JPG images because:

βœ… Lightweight
βœ… Browser renders directly
βœ… No server dependency
βœ… Works perfectly offline

Unlike PNG/JPG files, SVG does not require an additional server request.


πŸš€ Steps to Customize Offline Page

Step 1

Go to:

Shared Components

Step 2

Under:

Globalization β†’ Text Messages

Step 3

Click:

Create Text Message

Step 4

Enter Message Name:

APEX.PWA.OFFLINE.BODY

Step 5

Select the appropriate language.

Repeat for all supported languages.


Step 6

Enter your custom HTML / SVG / Text.

Example:

<div style="text-align:center;padding:40px;">

  <svg width="120" height="120" viewBox="0 0 24 24">
      <path fill="#1976D2"
            d="M12 2L1 21h22L12 2z"/>
  </svg>

  <h2>You Are Offline</h2>

  <p>
     Internet connection is currently unavailable.
     Your data will sync automatically once connection returns.
  </p>

</div>

πŸ”₯ Architecture Flow

User Enters Data
        ↓
Internet Available?
        ↓
   YES β†’ Save to Oracle DB
        ↓
   NO  β†’ Save to Local Storage
        ↓
Internet Restored
        ↓
Sync Local Data to Oracle DB

🎯 Advantages of Offline Strategy

βœ… No data loss
βœ… Better field usability
βœ… Faster response time
βœ… Improved user experience
βœ… Works in low-network areas


⚠️ Challenges in Offline APEX Apps

πŸ”Ή Conflict Resolution

What if the same record changes online and offline?

πŸ”Ή Data Security

Avoid storing sensitive data in local storage.

πŸ”Ή Browser Storage Limits

Local Storage has size limitations.

πŸ”Ή Sync Failures

Need retry logic for failed synchronization.


πŸš€ Advanced Enhancements

You can further improve the solution with:

βœ” IndexedDB instead of Local Storage
βœ” Background Sync API
βœ” Offline Queue Management
βœ” Sync Status Dashboard
βœ” Push Notifications


πŸ“Š Real-World Use Cases

This strategy is ideal for:

  • Logistics apps
  • Delivery tracking
  • Field inspections
  • Survey collection systems
  • Healthcare mobility solutions

πŸŽ‰ Conclusion

Oracle APEX makes Progressive Web Apps easy, but building a true offline-first application requires additional planning and strategy.

By combining:

βœ… PWA
βœ… Service Workers
βœ… Browser Local Storage
βœ… Offline Synchronization
βœ… Custom Offline Pages

you can create enterprise-grade applications that continue working even when the internet disappears.

This becomes a game changer for field workers and remote operations.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *