Comments (8)
Sounds like an issue across the wiki-client and plug-ins.
Think we need to add a function to the wiki-client that will add a requested resource, if it hasn't been added already. And, for the client to call that function when they want to add a resource.
Also need to check that the plug-in code is only getting loaded the once.
from wiki-server.
I've noticed that pages with many code items render slowly. I had guessed that it was dom manipulation or something else like that. It would be good to check this from the browser's inspector to find out what is really going on.
from wiki-server.
I created a simple page with thirty lines in a code plugin. Watching the network traffic in chrome on a shift-reload I saw that prettify.css was still loaded from cache. Strangely, prettify.js was loaded twice to render one code item. The prettify.js load included cache-busting random parameters so it really did load it twice.
I added a second code item to the page, reloaded, saw prettify.css still only loaded once, from cache, but prettify.js loaded four times, each time with a different parameter which I now recognize as a millisecond clock.
I added six more items for a total of eight code items. Rendering this page loads prettify.js 16 times. Yikes.
I haven't looked a code yet. But I'd expect there is something foolish in the code plugin, or in the utility that it calls to do the loading. I suggest we wait on working this issue further until our new code organization and build processes are stable. Then we should look into best practice for dynamic loading javascript and scoping the css that goes with it.
from wiki-server.
Interesting that prettify.css is only getting downloaded the once, looking in the DOM it is injected into the head multiple times, but I guess the browser has the sense to only fetch it the once.
A quick search gives this 👉 How to use Javascript to check and load CSS if not loaded?.
In wiki-plugin-code, the load is
load = (callback) ->
wiki.getScript '/plugins/code/prettify.js', callback
$('<style type="text/css"></style>')
.html('@import url("/plugins/code/prettify.css")')
.appendTo("head");
wiki.getScript
is defined over in wiki-client/lib/plugin.coffee. And, from a quick step through, it looks as if the problem is in
scripts = {}
getScript = wiki.getScript = (url, callback = () ->) ->
if scripts[url]?
callback()
else
$.getScript(url)
.done ->
scripts[url] = true
callback()
.fail ->
callback()
the scripts[url]?
always appears to be false, so the script is loaded multiple times.
think this should be something more like
scripts = []
getScript = wiki.getScript = (url, callback = () ->) ->
if url in scripts
callback()
else
$.getScript(url)
.done ->
scripts.push url
callback()
.fail ->
callback()
will probably try this in the morning.
from wiki-server.
I added a second code item to the page, reloaded, saw prettify.css still only loaded once, from cache, but prettify.js loaded four times, each time with a different parameter which I now recognize as a millisecond clock.
See Caching Responses on jQuery.getScript, probably setting cache to true is an option.
But, there remains the question of why it is loaded twice rather than just the once for each code block.
from wiki-server.
Digging a bit deeper, looking at why prettify.js is getting loaded twice - writing the url and callback to the console when wiki.getScript is called. We see
in wiki-plugin-code/code.coffee the load is getting called twice, once for the emit, and again for the bind. Both are calling wiki.getScript - so, the script is getting loaded twice.
Will probably add the code so that jQuery.getScript will cache the load, but as both are happening in parallel I don't expect it to solve this problem.
Adding code so that the getScript call is cache results in the script just getting loaded the once, extract from the server logs below.
from wiki-server.
I feel an architectural weakness in our approach to dynamic loading of both plugins and the resources plugins need. We've lived with this for some time. I'd be happy to see these weaknesses patched or even ignored while we work on bigger problems. That said, this is some suggestions I've received from wise people regarding loading plugins:
- Don't bother to load plugins dynamically. Use browserify to make one download and compresses it for speed.
- Make a "boot loader" for each plugin that is tiny. Have it orchestrate the loading of what ever it needs and hand out promises so that others can find these resources.
- Dynamic loading is a solved problem. Get one that works. Don't write your own.
What we have now is the result of taking lots of advice from Stack Overflow and then moving on once things seemed to work. This is a good way to get a feel for what you really need but doesn't lead to software well aligned with our dynamic environment.
I'd like to revisit dynamic loading once we have some more experience writing and maintaining plugins in our new repo configuration. This could include a rethink of how the core interacts with plugins.
from wiki-server.
I'd be happy to see these weaknesses patched or even ignored while we work on bigger problems.
In some respects, this issue has help with the refactor - I have been keeping notes on the steps I have been following.
I propose that we only apply the changes for the refactored node version (the ruby version will pick-up the change when it is refactored to use the new repositories).
from wiki-server.
Related Issues (20)
- Fedwiki on Raspberry Pi2 HOT 8
- Stealth Persona Disabling in Farm Mode HOT 4
- How to run wiki as a daemon and keep it alive HOT 2
- Browserified Fedwiki HOT 5
- server doesn't understand scoped modules when looking for plugins HOT 4
- Could this be a server plugin?
- HTML Title marked incorrectly HOT 3
- Plugin Installation Issue HOT 2
- URLs with line-up with sites other than the origin not working HOT 3
- Wiki@Next : Claiming wiki HOT 1
- sanitize-caja changed namespace HOT 1
- Add routing configuration to server for Welcome Visitors Page HOT 6
- Console output in Farm Mode does not expose Request Hosts HOT 3
- Make sitemap generation protect against overlong synopsis HOT 2
- Item IDs absent from rendered HTML HOT 3
- bad or empty page json should be ignored HOT 3
- cookie sameSite: 'strict' causes failure of OAuth2 authentication HOT 2
- switch from coffeescript to javascript HOT 1
- How to specify admin in config.json with "security_type": "friends" HOT 6
- Only include wiki pages in index HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wiki-server.