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

Optimize Syntax Highlighting #111

Merged
merged 4 commits into from
May 3, 2017
Merged

Optimize Syntax Highlighting #111

merged 4 commits into from
May 3, 2017

Conversation

chrislopresto
Copy link
Owner

@chrislopresto chrislopresto commented May 1, 2017

This PR swaps out https://github.com/johnotander/ember-remarkable for https://github.com/gcollazo/ember-cli-showdown. This allows us to accomplish a few more things in this PR:

  • Load highlight.js from its CDN host asynchronously, thus removing the highlight.js source from the ember-freestyle payload
  • Remove ember-freestyle's bower dependencies

This reduces the vendor.js payload size by a lot. Here's the before / after for the addon's dummy app:

master

❯ ember build dist --environment=production

File sizes:

  • dist/assets/dummy-5020f5f9d9ca2b3f3cf14150ddc1f2fb.css: 2.66 KB (1.12 KB gzipped)
  • dist/assets/dummy-74e7dd1657be3542306d9b8a913f5e91.js: 27.48 KB (4.3 KB gzipped)
  • dist/assets/vendor-dc56a46fe6d7e24c94d86089d6ee07a1.css: 31.74 KB (4.17 KB gzipped)
  • dist/assets/vendor-3764fa2de49a993c6fa7034c58ee0345.js: 1.21 MB (364.24 KB gzipped)

showdown

❯ ember build dist --environment=production

File sizes:

  • dist/assets/dummy-5020f5f9d9ca2b3f3cf14150ddc1f2fb.css: 2.66 KB (1.12 KB gzipped)
  • dist/assets/dummy-111fca9208cd0c8bdc0314a25da99245.js: 27.29 KB (4.3 KB gzipped)
  • dist/assets/vendor-75cb9593fb1c61ccd48785d8ab1871d0.css: 17.12 KB (2.72 KB gzipped)
  • dist/assets/vendor-de35e537624def089c5ab78a71dfe7f1.js: 677.89 KB (180.78 KB gzipped)

Resolves #13
Resolves #14
Resolves #31
Resolves #80
Resolves #81
Resolves #84
Resolves #105

/cc @lukemelia

ensureHljs() {
if (!hljsPromise) {
hljsPromise = new Promise((resolve) => {
return Ember.$.getScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/highlight.min.js').done((script) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to consider adding a timeout and/or offline check, so that styleguides are usable offline (without syntax highlighting).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe this will just work as is. We could add a catch that logs the fact that syntax highlighting is not available.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The components render without syntax highlighting and happily wait for the ensureHljs promise to resolve. The highlight.js highlight call is chained off of that, so it all seems to work safely and nicely.

A log message indicating that syntax highlighting isn't available because of a timeout could be nice.


const { computed } = Ember;

export default MDTextComponent.extend({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider this component public API? We could consider leaving a stub version of the component that throws an error instructing the user what to use instead.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component never made it into a released version. Earlier versions of freestyle were using the md-text component provided by (my fork of) ember-remarkable.

I switched over to this approach to get off of my ember-remarkable fork before realizing ember-cli-showdown + highlight.js-via-CDN would come together so nicely.

@lukemelia
Copy link
Collaborator

Huge win!

@chrislopresto chrislopresto force-pushed the showdown branch 3 times, most recently from 8b4d4b9 to bd171a4 Compare May 3, 2017 02:51
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

Successfully merging this pull request may close these issues.

2 participants