Skip to content

Conversation

@fadi-george
Copy link
Contributor

@fadi-george fadi-george commented Oct 17, 2025

Description

1 Line Summary

  • more size reduction
// old
  build/releases/OneSignalSDK.page.js
  Size limit: 420 B
  Size:       420 B gzipped
  
  build/releases/OneSignalSDK.page.es6.js
  Size limit: 47.56 kB
  Size:       47.56 kB gzipped
  
  build/releases/OneSignalSDK.sw.js
  Size limit: 13.62 kB
  Size:       13.62 kB gzipped
  
  build/releases/OneSignalSDK.page.styles.css
  Size limit: 8.81 kB
  Size:       8.8 kB  gzipped


// new
  build/releases/OneSignalSDK.page.js
  Size limit: 420 B
  Size:       420 B gzipped
  
  build/releases/OneSignalSDK.page.es6.js
  Size limit: 46.6 kB
  Size:       46.6 kB gzipped
  
  build/releases/OneSignalSDK.sw.js
  Size limit: 13.44 kB
  Size:       13.44 kB gzipped
  
  build/releases/OneSignalSDK.page.styles.css
  Size limit: 8.81 kB
  Size:       8.8 kB  gzipped

Details

  • breaks up main helper class into exported functions
  • breaks up service worker class into functions
  • breaks up limit store class into functions
  • adds more underscore prefix for more classes
  • removes unused path class methods
  • breaks up tags utils class into functions
  • adds webhook sender class into functions since sender class was also broke up into a simple send function
  • removed self.OneSignalWorker as it is not needed

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets



This change is Reviewable

this.path = path.trim();
}

getQueryString(): string | null {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

@@ -0,0 +1,47 @@
/*
LimitStore.put('colorado', 'rocky');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to use new function name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

store[key] = [null, null];
}
store[key].push(value);
if (store[key].length == LIMIT + 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using strict equality

Suggested change
if (store[key].length == LIMIT + 1) {
if (store[key].length === LIMIT + 1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

declare const self: ServiceWorkerGlobalScope;
self.OneSignalWorker = OneSignalServiceWorker;
// The run() is already called in ServiceWorker.ts, but importing it ensures it's not tree-shaken
void run;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need confirmation that this actually works: e.g. does it actually make it to the final bundle? Even then, this approach seems confusing and potentially fragile.

I'm suspicious that it's not needed especially because run is already invoked at the top-level here.

My suggestion would be to either move that line here

import { run } from '../sw/serviceWorker/ServiceWorker';

run();

or import the entire file (although the bundle size may take a hit)

import '../sw/serviceWorker/ServiceWorker';

// The run() is already called in ServiceWorker.ts, but importing it ensures it's not tree-shaken
void run;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both work but for now ive moved run called to worker.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this call be removed then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is removed

@fadi-george fadi-george merged commit 8b56676 into main Oct 24, 2025
3 checks passed
@fadi-george fadi-george deleted the fg/size-reduction-4 branch October 24, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants