Skip to content

SDK-2919 Minify / Mangle constant keys#1357

Merged
fadi-george merged 3 commits intomainfrom
fadi/sdk-2919-mangleminify-constants-keys
Aug 25, 2025
Merged

SDK-2919 Minify / Mangle constant keys#1357
fadi-george merged 3 commits intomainfrom
fadi/sdk-2919-mangleminify-constants-keys

Conversation

@fadi-george
Copy link
Copy Markdown
Contributor

@fadi-george fadi-george commented Aug 22, 2025

Description

1 Line Summary

  • Use terser minification instead of esbuild

Main:

build/releases/OneSignalSDK.page.js
  Size limit: 490 B
  Size:       490 B gzipped
  
  build/releases/OneSignalSDK.page.es6.js
  Size limit: 54.81 kB
  Size:       54.81 kB gzipped
  
  build/releases/OneSignalSDK.sw.js
  Size limit: 15.3 kB
  Size:       15.29 kB gzipped
  
  build/releases/OneSignalSDK.page.styles.css
  Size limit: 8.81 kB
  Size:       8.8 kB  gzipped

Now:

  build/releases/OneSignalSDK.page.js
  Size limit: 450 B
  Size:       450 B gzipped
  
  build/releases/OneSignalSDK.page.es6.js
  Size limit: 52.32 kB
  Size:       52.32 kB gzipped
  
  build/releases/OneSignalSDK.sw.js
  Size limit: 14.56 kB
  Size:       14.56 kB gzipped
  
  build/releases/OneSignalSDK.page.styles.css
  Size limit: 8.81 kB
  Size:       8.8 kB  gzipped

Details

  • Add terser package and changes the default minifier (via vite.config) to terser. This will minify object keys like 'SafariLegacyPush' where only value matters.
Screenshot 2025-08-22 at 11 34 45 AM Screenshot 2025-08-22 at 11 34 05 AM

Otherwise, for esbuild we would have to setup:

  esbuild: {
      mangleProps: /^_[A-Z]/,
    },

And then put underscores on every constant e.g.

export const OPERATION_NAME = {
  // Identity Operations
  _SET_ALIAS: 'set-alias',
  _DELETE_ALIAS: 'delete-alias',

  // Property Operations
  _SET_PROPERTY: 'set-property',

  // User Operations
  _REFRESH_USER: 'refresh-user',
  _LOGIN_USER: 'login-user',

  // Subscription Operations
  _CREATE_SUBSCRIPTION: 'create-subscription',
  _UPDATE_SUBSCRIPTION: 'update-subscription',
  _DELETE_SUBSCRIPTION: 'delete-subscription',
  _TRANSFER_SUBSCRIPTION: 'transfer-subscription',

  // Custom Events Operations
  _CUSTOM_EVENT: 'custom-event',
} as const;

Which would be a lot of work.

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

@fadi-george fadi-george force-pushed the fadi/sdk-2919-mangleminify-constants-keys branch from aaf55f2 to 0ea6f3e Compare August 22, 2025 18:50
- remove redundant environment constants
@fadi-george fadi-george force-pushed the fadi/sdk-2919-mangleminify-constants-keys branch from dae803e to 51e0b95 Compare August 25, 2025 17:23
@fadi-george fadi-george merged commit c36a072 into main Aug 25, 2025
4 checks passed
@fadi-george fadi-george deleted the fadi/sdk-2919-mangleminify-constants-keys branch August 25, 2025 17:26
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