Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize browser bundle size #2

Open
SpaceK33z opened this issue Dec 1, 2016 · 9 comments
Open

Minimize browser bundle size #2

SpaceK33z opened this issue Dec 1, 2016 · 9 comments

Comments

@SpaceK33z
Copy link

Director used a trick to remove parts of lib/tarantino/router.js that are not necessary for the browser version (see here). This removed 10kb of the non-minimized bundle.

I'd prefer to solve this by extracting router.js in two parts.

@mhulse
Copy link

mhulse commented Jan 31, 2017

Love to see this as well. I would not mind doing a PR. I have yet to clone this repo to run builds. Does the CONTRIBUTING.md file cover the bases for development/PR stuff? Any tips, specific to this code, to make the process adding features and doing a PR (specific to this code) easier?

@SpaceK33z
Copy link
Author

To fix this, some functions of lib/tarantino/router.js that are only used by the non-browser version should be moved to a separate file. In Director this was solved with a really creative (ugly) hack, which you can see here. Essentially the build script removed those lines from the browser version.

I'd propose to fix this by making a separate file and never import that file for the browser version.

@mhulse
Copy link

mhulse commented Jan 31, 2017

Your proposal sounds good to me.

I should have some time this week and upcoming weekend to dig into helping out. Let me see if I can do a PR for this. I'll let you know either way.

@mhulse
Copy link

mhulse commented Feb 2, 2017

Looking at this, they extract() these methods/var:

'QUERY_SEPARATOR',
'_flatten',
'_every',
'_asyncEverySeries',
'paramifyString',
'regifyString',
'terminator',
'Router.prototype.configure',
'Router.prototype.param',
'Router.prototype.on',
'Router.prototype.path',
'Router.prototype.dispatch',
'Router.prototype.runlist',
'Router.prototype.invoke',
'Router.prototype.traverse',
'Router.prototype.insert',
'Router.prototype.insertEx',
'Router.prototype.extend',
'Router.prototype.mount'

With the exception of Router.prototype.insertEx (which is found in lib/browser.js), all of the above can be found in lib/tarantino/router.js.

I think I am a little confused as to what to do here.

Looking at the rollup files, as far as I can tell, the code is already grabbing the browser-specific code found in lib/browser.js (which imports lib/tarantino/router.js).

Correct me if I am wrong, but isn't lib/tarantino/cli.js and lib/tarantino/http/* the node-specific versions?

If I am reading things correctly here, I think this issue has already been resolved?

Of course, I could be overlooking something totally obvious. 😆

@mhulse
Copy link

mhulse commented Feb 7, 2017

@SpaceK33z, I am sure you are busy, but do you have any thoughts on my previous comment?

I think my base question is this:

Is the browser code already minimized?

This issue reminds me of this thought: We should separate the browser code from the node code into their own repos. 👍

Thanks!

@SpaceK33z
Copy link
Author

Yes I'm a bit busy now, but some quick things;

The methods/vars you mention get extracted out of the browser bundle because they are not necessary/used for the browser. This saves some bytes. However, our Rollup bundle doesn't do that same trick. It still includes these methods/vars for the browser bundle.
The way they remove these methods/vars is very hacky I think, so we could look into a better solution. Perhaps make a separate file for it and only import that file for Node.js

I think I don't agree with separating into repositories. We need to organize the code a bit better, but part of the power of this package is that it works almost the same for both platforms. They use the same codebase + some platform-specific code. We just have to make sure that the browser only loads the minimum amount of code necessary.

@mhulse
Copy link

mhulse commented Feb 7, 2017

The methods/vars you mention get extracted out of the browser bundle because they are not necessary/used for the browser. This saves some bytes. However, our Rollup bundle doesn't do that same trick. It still includes these methods/vars for the browser bundle.
The way they remove these methods/vars is very hacky I think, so we could look into a better solution. Perhaps make a separate file for it and only import that file for Node.js

Ok, that definitely helps to explain things better.

EDIT/REMOVED (I was confusing browser.js with the router.js file. I see now what needs to be done.

Now that you clarified, I will take another look. 👍

I think I don't agree with separating into repositories. We need to organize the code a bit better, but part of the power of this package is that it works almost the same for both platforms. They use the same codebase + some platform-specific code. We just have to make sure that the browser only loads the minimum amount of code necessary.

No worries and thanks for the reply/help! :octocat:

@mhulse
Copy link

mhulse commented Feb 7, 2017

Ok, sorry for the commotion; I see now what needs to be done. Thanks again for the clarification! 👍

@SpaceK33z
Copy link
Author

No problem, I'm glad you're helping out 💯

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

No branches or pull requests

2 participants