Skip to content

Replace moment.js with day.js for smaller bundle size #795

@GaryJones

Description

@GaryJones

Summary

Replace moment.js with day.js to reduce JavaScript bundle size. moment.js is deprecated and significantly larger than modern alternatives.

Why

Library Size (minified + gzip) Status
moment.js ~67 KB Deprecated, in maintenance mode
day.js ~2 KB Active development, similar API

Bundle impact: ~65 KB reduction (moment.js is currently in the vendor chunk)

Current Usage

// src/react/utils/extendedMoment.js
import moment from 'moment';
const date = moment(timestamp).fromNow();

Used for:

  • Relative timestamps ("5 minutes ago")
  • Date formatting in entries
  • Locale-aware date display

Migration Path

// After
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);

const date = dayjs(timestamp).fromNow();

Potential Issues

  1. Locale handling - day.js loads locales separately (good for bundle size, but needs explicit import)
  2. Plugin system - Some moment features require day.js plugins:
    • relativeTime - for .fromNow()
    • localizedFormat - for locale-aware formatting
    • utc - for UTC operations (if used)
  3. API differences - Minor, but need to verify all usages:
    • Both use .format(), .fromNow(), .diff()
    • day.js is immutable by default (moment mutates)

Tasks

  • Audit all moment.js usage in codebase
  • Install day.js: npm install dayjs
  • Update src/react/utils/extendedMoment.js
  • Test all date displays across locales
  • Remove moment.js: npm uninstall moment
  • Verify bundle size reduction

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions