silverwind / droppy

**ARCHIVED** Self-hosted file storage
BSD 2-Clause "Simplified" License
1.62k stars 193 forks source link

CodeMirror: Load modes on demand #182

Closed silverwind closed 9 years ago

silverwind commented 10 years ago

As discussed: https://github.com/silverwind/droppy/issues/43

colelawrence commented 10 years ago

Related: #146 Can use a library like basket.js

silverwind commented 10 years ago

Also worth investigating if we can load CM itself on demand, which should reduce initial page load a lot as CM is 50% of our JS resources.

colelawrence commented 10 years ago

Can also add an option to use a cdn for codemirror.

CM is 50% of our JS resources.

Be thankful we aren't using Ace! haha

Honestly though, our page load time and size is stellar compared to any other comparable software out there.

It can't hurt to "lazy-load" CodeMirror though.

silverwind commented 10 years ago

I've avoided CDNs until now as I'd like to keep droppy working in an offline scenario with a LAN server.

Guess I can't complain about loading times. The demo is at 1.8s first-load, 0.9s cached. Locally, I'm at around 0.5s/0.3s which is probably alright, but especially in regards to performance, I'm strifing for perfection. :)

colelawrence commented 10 years ago

Loading times includes script exec?

silverwind commented 10 years ago

I think so, yes. It's what Firefox shows in the devtools statusbar.

colelawrence commented 10 years ago

Golly goodness.

silverwind commented 9 years ago

TODO:

silverwind commented 9 years ago

I might need a bit of CodeMirror assistance here for modes. I'm dynamically filling a <script> with the current mode, the console prints confirm that the mode gets loaded into CodeMirror.modes

"CodeMirror.modes before" Array [ "null" ]
"CodeMirror.modes after" Array [ "null", "javascript" ]

But still no syntax highlighting to be seen. Also, html mode gives an rather strange TypeError in the console, not sure what's wrong.

TypeError: htmlMode.startState is not a function
silverwind commented 9 years ago

Might have to do something like this:

https://github.com/marijnh/CodeMirror/blob/master/addon/mode/loadmode.js

silverwind commented 9 years ago

Can certainly optimize the code a bit more, but this works now. :+1:

silverwind commented 9 years ago

Initial load down to about 1.2s from 1.8s Cached load down to about 0.7s from 0.9s

I might have to remove that loading animation circle soon. :tongue:

colelawrence commented 9 years ago

You do not need to do any extra work than loading the mode script, and if the mode script is not loaded it falls back to plain text.

On Fri, Sep 5, 2014 at 4:08 PM, silverwind notifications@github.com wrote:

I might need a bit of codemirror assistance here for modes. I'm dynamically filling a Githubissues.

  • Githubissues is a development platform for aggregating issues.