dspace-angular icon indicating copy to clipboard operation
dspace-angular copied to clipboard

Shrink size of Klaro & ban wildcard imports.

Open tdonohue opened this issue 3 years ago • 1 comments

References

This PR continues to try to decrease the size of main.js.

  • This PR includes the changes in #1903 (so it is smaller than it appears)

This PR decreases the GZipped size of main.js by an additional ~15KB. (on top of the ~66KB decrease of #1903, totaling a ~81KB decrease). This measurement was determined by running the following on main vs this PR:

  • yarn build:stats
  • webpack-bundle-analyzer .\dist\browser\stats.json

Description

This PR updates the following:

  • Bans usage of wildcard imports (except where required). This ensures these wildcard imports don't accidentally import an entire library when all we need is a few features of the library. (This change doesn't appear to have shrunk main.js much, but it's a safety measure to avoid future growth of main.js)
    • For example, this is not allowed: import * as fs from 'fs';
    • Instead, you should do something like: import { existsSync, writeFileSync } from 'fs';
  • Replaced wildcard imports where possible to do so. (For some mini-libraries this is not possible. But they are exceptions to the new rule.)
  • Upgrade to latest Klaro
  • Switch to importing klaro-no-translations, which excludes the built in translations in Klaro & decreases the size of Klaro. This is because we are already translating much of Klaro in our existing src/assets/i18n/*.json5 files. Added a few more keys to ensure all of Klaro is translated in DSpace.

Instructions for Reviewers

  • Test Klaro cookie popup. Use Incognito mode to verify the Klaro popup is fully translated. Switch to a different language and verify it is still mostly translated (there may be a few English words still if the *.json5 translation pack you select is missing a few keys).
  • Review code changes.

tdonohue avatar Oct 17 '22 19:10 tdonohue

@artlowel : Assigning to you for review as you volunteered to look at shrinking main.js. Please feel free to delegate if you wish.

tdonohue avatar Oct 20 '22 15:10 tdonohue

@ybnd : I've addressed your prior feedback. If you could give this a quick rereview, I'd appreciate it!

tdonohue avatar Oct 27 '22 21:10 tdonohue