Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Improve collection loading for huge websites #609

Closed
DavidWells opened this issue Aug 10, 2016 · 21 comments · Fixed by #936
Closed

Improve collection loading for huge websites #609

DavidWells opened this issue Aug 10, 2016 · 21 comments · Fixed by #936

Comments

@DavidWells
Copy link
Contributor

Just tested out a 1000 page site. Generated them with this handy script: https://gist.github.com/DavidWells/a75045c89d6f3d453ef4ab68499550f4

Good news, the build only took like 60 seconds!

The generated site was 296mb in total though. This was primarily due to every page inlining the entire window.__COLLECTION__ into the html. (https://gist.github.com/DavidWells/675b1b838c44925d6487fff3cc129674)

The window.__COLLECTION__ makes html files weight 300k vs 8k

Perhaps there is a way to lazy load in the routing data and stick it inside localstorage or a service worker?

Or build the window.__COLLECTION__ into a single collection.js file and include that once in the head tag? Then it could be cached and would make all the html files lighter.

@thangngoc89
Copy link
Contributor

Hi, thanks for sugessting this. The collection used to be in a seperated collection.json file and we used to load it async on initial load but it introduces some caveats.

@MoOx I think dumping it to collection.js and loading it in a blocking way would be the best. (Or non-blocking way if you can fix previous problems)

@DavidWells i tried phenomic on a REAL 10k pages site. The build time is about 8mins and the generated site is 800MB.

@thangngoc89
Copy link
Contributor

Well, why did we inject collection to html

#92

@MoOx
Copy link
Owner

MoOx commented Aug 10, 2016

We injected collection for better consitency between client & static build. And for small website, extra http request is not necessary. Obviously for large website it might seems huge, but at the end a single user is supposed to access a single html per session.
We could add a non lazy load of the collection via any method, but the collection should be mandatory for the client sync/rendering.

@DavidWells
Copy link
Contributor Author

DavidWells commented Aug 10, 2016

Maybe there could be an option to inline or include collections via:

<script src"/collestions.js?hashXyzydhhs231313123123" async></script>

Larger sites could opt for script tag and save on overall site size.

(in my 1000 page test) Each inlined collection adds 292kb to the file size. So an addition 292mb for a site at 1000 pages.

With the script tag it would be the single 292kb and the deploy/storage would be sooooo much smaller =)

@MoOx
Copy link
Owner

MoOx commented Aug 10, 2016

That's definitely something we should do. We could even ask the user during the deployment if we want collection to be outside html (if let say collection > 150kb?) and save the pref in package.json for future build?

@DavidWells
Copy link
Contributor Author

This will make larger sites way more viable and cost friendly

@DavidWells
Copy link
Contributor Author

@MoOx I'd like to take a stab at adding this option.

Would here:

<script>
window.__COLLECTION__ = ${
serialize(collectionMin)
};
</script>
be the correct place to add the logic to take the collection and add it to script tag instead of inlining?

@thangngoc89
Copy link
Contributor

@DavidWells I think it's best to leave it there. It's the dev server. For static build, you should change this line

script =
`window.__COLLECTION__ = ${
serialize(collectionMin)
};` +
(extract it to a external js file instead of inline it)

@MoOx
Copy link
Owner

MoOx commented Aug 16, 2016

You will also have to emit a collection.json file from Phenomic loader in addition to previous additions you both mentionned.

@MoOx MoOx changed the title 1000 page site test Improve collection loading for huge websites Aug 16, 2016
@thangngoc89
Copy link
Contributor

@MoOx it should be collection.js. Let's the browser load that synchronously for us.

@MoOx
Copy link
Owner

MoOx commented Aug 16, 2016

Btw, we should replace window.__* by window.__PHENOMIC__.* or something like that... Maybe just window.Phenomic.*.

@thangngoc89
Copy link
Contributor

thangngoc89 commented Aug 16, 2016

I prefer window.__Phenomic.* . Who know what can a user put to the page.

@MoOx
Copy link
Owner

MoOx commented Aug 16, 2016

Then, window.__PHENOMIC_DONT_USE_THIS_OR_YOU_WILL_BE_FIRED__.*.

More seriously, I will probably use window.__PHENOMIC_PRIVATE_REGISTRY_YOU_SHOULD_NOT_RELY_ON__*.

@thangngoc89
Copy link
Contributor

@MoOx

window.PHENOMIC_DONT_USE_THIS_OR_YOU_WILL_BE_FIRED.*.

this is from React code base right ? I like the idea but we referenced this at many places. I don't want to type this everytime

@MoOx
Copy link
Owner

MoOx commented Aug 16, 2016

I plan to add public methods like import { getCollection } from "phenomic".

@thangngoc89
Copy link
Contributor

Great idea !

@thangngoc89
Copy link
Contributor

@DavidWells any update?

@DavidWells
Copy link
Contributor Author

@thangngoc89 how do you think we should implement this?

Are config options available in this context?

script =
`window.__COLLECTION__ = ${
serialize(collectionMin)
};` +

I can see a couple ways to turn this on:

  • A command line arg phenomic build --smallHTML(whatever)
  • A config option in package.json
  • A webpack config flag?

What do you think?

@thangngoc89
Copy link
Contributor

This should be a phenomic's config. FYI all configs in Phenomic can be altered via a cli flag or an entry in package.json/phenomic.

For adding a new config, see this file https://github.com/MoOx/phenomic/blob/2b44e19bfa095d2a4bb512c122dbb24380a83ef1/src/configurator/definitions.js

If you need some validation, add one in validators folder

@thangngoc89
Copy link
Contributor

thangngoc89 commented Aug 22, 2016

As for accessing the config, this func

export default function(
have access to PhenomicConfig object

It can be re-writtten like this: export default (url: String, config: PhenomicConfig, testing?: Boolean)

I hope these information are helpful

@bloodyowl
Copy link
Contributor

Going to be fixed with #925

@MoOx MoOx mentioned this issue Jan 12, 2017
Merged
@MoOx MoOx closed this as completed in #936 May 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants