Skip to content

Reduce the size of loopback client bundle #989

Closed

Description

@bajtos

At the moment, a browserified loopback module has about 1.4MB uncompressed, 650KB compressed. This size is unacceptable, especially for mobile browsers on a slow internet connection. We need to get at least below 100kb.

This GH issue is a time-scoped story. The goal is to analyse the dependencies, fix as many low-hanging fruits as possible and then create follow-up stories for the unsolved items.

Subtasks:

Activity

  1. self-assigned this
    on Jan 9, 2015
  2. added this to the #Epic: Offline Sync V1 milestone on Jan 9, 2015
  3. BerkeleyTrue commented on Mar 6, 2015

    @BerkeleyTrue
    Contributor

    @bajtos any advice or strategies on this?

  4. bajtos commented on Mar 9, 2015

    @bajtos
    MemberAuthor

    My plan is to produce profiling data using file (bundle) size instead of execution time, so that we can identify the files and modules that contribute most to the overall size. There may be an existing browserify module for that, I did not check yet. (Please let me know if you figure out how to do this.)

    Once we have that information, it should be easy to pick the biggest dependencies, check if they are used by the browser client, and exclude them using browser field in the relevant package.json field if they are not needed.

  5. BerkeleyTrue commented on Mar 10, 2015

    @BerkeleyTrue
    Contributor

    So the first step is to get the size of each file/script in the bunde?

  6. bajtos commented on Mar 10, 2015

    @bajtos
    MemberAuthor

    For each file/script, you need two values: the size of the file itself, and the cumulated size of all dependencies including the file itself.

    For example, a single-line file var loopback = require('loopback') is small itself (about 20 bytes), but huge when dependencies are included (1.4MB).

  7. 8 remaining items

  8. mattaylor commented on Jul 30, 2015

    @mattaylor

    Any movement here? This issue really renders offline / isomorphic usecases for loopback unworkable in production

  9. LucaColonnello commented on Aug 18, 2015

    @LucaColonnello

    +1

  10. jantimon commented on Aug 28, 2015

    @jantimon

    "This issue really renders offline / isomorphic usecases for loopback unworkable in production"
    We decided not to use loopback / strongloop just because this issue.
    People are complaining that jQuery has 35kb and this is too much for mobile.

    A rest library with 2-5 models should not consume more than 50kb gziped.

    Maybe you should provide another entry point with has just the client network stack and model definitions instead of browserifying tons and tons of server code.

    pouchdb is doing the same job and requires only 45kb: http://pouchdb.com/

  11. ritch commented on Aug 28, 2015

    @ritch
    Member

    Maybe you should provide another entry point with has just the client network stack and model definitions instead of browserifying tons and tons of server code.

    +1 for this

    Its really not as out of reach as it might sound. I think @bajtos has mentioned some of the steps to do this.

    This is what I'd like to see:

    • a build script (eg. a gulp file) included with the boilerplate of loopback (output of slc loopback)
    • outputs a browser version of your client directory
    • the build will exclude and shim modules to make the bundle a reasonable size
    • only includes modules required by your configuration (also in the build script).
      • eg.hasPassword() will not be supported and its deps will be shimmed with empty modules
    • allowing you to opt into features that require significantly larger modules
  12. acao commented on Aug 28, 2015

    @acao

    This is great!

    One of the biggest issues though, it seems, is compacting the size of the datasource juggler. This and loopback seemed to be the largest modules in the bundle.

    I'm with @jantimon. I've used pouchdb before and it's great and achieves a lot for a small library. We could probably come up with a thin client ODM that works like loopback datasource juggler without necessitating all the cruft of loopback itself. Like he was suggesting, on client boot it would request a payload of model definitions, learn about additional REST endpoints, etc. Then there could be simplified loopback-connectors for localstorage, pouchdb, linvodb3, etc for client-focused implementations.

    Generally, the real need becomes a much greater modularization of looback and the datasource juggler if you plan on continuing to bundle any of this together for the browser, especially with optional modules. Currently it appears to be all or nothing.

    Another idea is this - what if we were to build a library that could be used to inflect the logic of the loopback ODM into customized generators, as defined by your application? So you could create generators for angular $resource, ember data, for superagent and/or for flux implementations, all from the same logic.

  13. TonyLuo commented on Sep 9, 2015

    @TonyLuo

    +1. I only use some models . Is any way to define which models should be generated and which should not be generated in the AngularJS client file?

  14. bajtos commented on Sep 9, 2015

    @bajtos
    MemberAuthor

    +1. I only use some models . Is any way to define which models should be generated and which should not be generated in the AngularJS client file?

    This issue (#989) is discussing the size of the client bundle produced by browserify.

    Please open a new issue in loopback-sdk-angular to discuss feature requests for the AngularJS client code generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions