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

Load site data asynchronously #621

Merged
merged 3 commits into from Feb 4, 2019

Conversation

marvinchin
Copy link
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [x] Enhancement to an existing feature

Resolves #608.

What is the rationale for this request?

To avoid having render being blocked on waiting for siteData.json to load, we first render the page then load it asynchronously.

What changes did you make? (Give an overview)

  • Embed the enableSearch variable in the HTML document
  • Update setup.js to fetch siteData.json asynchronously

Is there anything you'd like reviewers to focus on?

I've embedded the enableSearch variable in the HTML document to allow us to decide whether to use setup() or setupWithSearch() without first having to load siteData.json to preserve the original behavior. However, I was wondering whether or not it would be possible for us to simply use setupWithSearch() for both cases, since sites with search disabled cannot use the searchbar component anyway (see #620). This would allow us to avoid having to embed enableSearch in the HTML document.

Testing instructions:
Observe the chrome network tab. siteData.json should be loaded after the page is rendered completely.

<link rel="stylesheet" href="../markbind/css/bootstrap-glyphicons.min.css" >
<link rel="stylesheet" href="../markbind/css/github.min.css">
<link rel="stylesheet" href="../markbind/css/markbind.css">
<link rel="stylesheet" href="../markbind/layouts/default/styles.css">
Copy link
Member

Choose a reason for hiding this comment

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

We should be consistent with the slash direction, so let's stick to \.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should use /, especially for URLs. Is \ generated by Windows here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes \ is generated by Windows. We currently update test files by copying over content from _site to expected, so the slashes are going to change depending on the OS that the person is using when he/she updates the tests, which is not really ideal...

Maybe code-wise we should standardize how MarkBind output slashes for file paths (can be a separate PR for that).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@acjh @yamgent could I check if I should change the slash direction in my PR, or should we leave it to be fixed in another PR?

Thanks for looking into it!

Copy link
Member

Choose a reason for hiding this comment

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

could I check if I should change the slash direction in my PR, or should we leave it to be fixed in another PR?

Those will be dealt with by the person that is resolving #628.

@marvinchin
Copy link
Contributor Author

@yamgent I've made the changes!

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

However, I was wondering whether or not it would be possible for us to simply use setupWithSearch() for both cases, since sites with search disabled cannot use the searchbar component anyway (see #620). This would allow us to avoid having to embed enableSearch in the HTML document.

I am OK with unifying setup() and setupWithSearch() since the original reason why they were split was mainly because of siteData.json's existence.

However, for your last point, I don't see how this would result in not using enableSearch. If enableSearch is false, then getSearchData() should never be called, so you still need a way to determine the value of enableSearch.

@marvinchin
Copy link
Contributor Author

@yamgent if we do not use enableSearch, we can simply make the call to fetch siteData.json regardless of whether or not search is enabled. If enableSearch is disabled, then the call will be unnecessary but should not affect the rest of the site.

I suppose this is a tradeoff between making an unnecessary call, and injecting the enableSearch into the document. I was just thinking that injecting the variable into the document felt a little dirty, so I was thinking if there was any way to avoid that 😛

@acjh
Copy link
Contributor

acjh commented Jan 24, 2019

Downloading a file we won't use is bad.

@marvinchin
Copy link
Contributor Author

If that's the case, perhaps not unifying setup() and setupWithSearch() might still make sense, since that way we do not need to add the searchbar component or the required attributes/methods to the vue instance we are creating if enableSearch is false.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

One minor nit:

@@ -33,6 +33,14 @@ function setupAnchors() {
});
}

function getSearchData(vm) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename getSearchData() to updateSearchData() (methods with names that start with get are usually accessor methods).

@marvinchin
Copy link
Contributor Author

@yamgent fixed!

@marvinchin
Copy link
Contributor Author

@yamgent could I check if we are intending to merge this? Just wanted to let you know that I've resolved the merge conflicts! 🙂

@yamgent yamgent merged commit 75dbcf5 into MarkBind:master Feb 4, 2019
@yamgent yamgent added this to the v1.17.2 milestone Feb 4, 2019
@marvinchin marvinchin deleted the load-site-data-async branch March 20, 2019 14:16
@ang-zeyu ang-zeyu mentioned this pull request Jan 24, 2021
10 tasks
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.

None yet

3 participants