Khan / engblog

KA Engineering blog.
http://engineering.khanacademy.org
Other
29 stars 20 forks source link

Add async_scripts parameter to frontmatter. #33

Closed itsjohncs closed 9 years ago

itsjohncs commented 9 years ago

Now posts can specify scripts to add to the page. They will be added via <script async src="bla"></script> tags in the <head> section.

Test Plan: 1) Create an alert.js file in src/javascript/ and write alert("hello") in it. 2) Add /javascript/alert.js as an async script for one of the posts. 3) Run make serve and go to the post page. See the alert pop up.

itsjohncs commented 9 years ago

@WChargin Can you look this over and make sure this satisfies your use case?

itsjohncs commented 9 years ago

This satisfies part of #2.

wchargin commented 9 years ago

Thanks, John! I can make this work. It'd be great if we could include fonts, too (KaTeX has a few dozen), but that doesn't look as immediately simple given that you're inlining all the CSS. If you're okay with using cdnjs's hosted version of KaTeX then we're fine.

I've also added stylesheets and postcontent_scripts (document-inline script tags) so I'll submit those in a separate diff.

itsjohncs commented 9 years ago

Cool! I forgot about the stylesheet :(. It's a bit of a bummer that we don't have the infra in place to inline the CSS for just one post. I won't have time to add that by the time it's time for you to post, so I'm fine with just loading it in a script like your PR suggests.

Though if it's not that big, consider adding it to the CSS that gets loaded into every page. The one-round-trip performance gain would probably outweigh the disadvantage in size of pages that we'd get. Do you know if that'd be reasonable @WChargin?

wchargin commented 9 years ago

It's 18K, so inlining it probably would be faster. But if you look at the stylesheet, it expects fonts to be in the same directory as the stylesheet. Wouldn't that break if it were inlined?

We could change the stylesheet to use absolute paths (change fonts/ to /fonts/) if we also served the fonts statically. It looks like all unknown paths just silently serve /?

itsjohncs commented 9 years ago

Ah I see. Yeah, that wouldn't go over super well (though you could also host the fonts too, which wouldn't be a big deal). Loading fonts from the stylesheet would also kill the one-round-trip-ness which would be bad. External assets seem to be the way to go right now.