Whats with all the json at the top of my posts?


#1

Hi all,

What’s with all the json at the top of my posts? For example, with this one:

There’s a good hundred lines or so with json. How can I remove this/does it serve a purpose?

Thanks


Should I upload all of _site to Github Pages?
#2

Looks like it is data for Lunr Search. Possibly part of the theme or custom layout?


#3

Thanks, makes sense. I am guessing it won’t have an impact on site speed?

Thanks


#4

For the moment, it’s not a big impact, but the text from all blog pages is reproduced on every page. That seems wasteful, and eventually it is going to slow page loads down when there are hundreds of posts.

You should check how Lunr is installed (maybe theme, plugin, etc), and see if there are options for a more efficient setup, like on-demand loading, etc.


#5

Will do, thank you very much!


#6

@DipperDolphin, I have built something interesting based on jekyll_pages_api_search plugin, so that my search index (large piece of json) is only loaded when search results are rendered (not when search button is hit).

Since readers (including myself) use search feature less often than they fetch individual pages of content and therefore, it might be okay for the reader to wait a bit while the search index is loaded, parsed and rendered.

You can see it in action in my blog, here: pabloduo.com

Search is available on any page:

Entering search query:

Rendering search results:


#7

Looks interesting. I am actually using this theme: https://github.com/wowthemesnet/mediumish-theme-jekyll. I’m also hosting on Github pages so I am not sure if that plugin is supported on GH :smiley:

And am now only having the issues when I build the site. It was working fine when I didn’t have _site, but I need that for the sitemap.

Any idea how I can fix it? I have a little, but not much, experience with Jekyll and Ruby.

Thanks!


#8

Anyone have any idea how to fix this?

Thanks


#9

You need to modify the theme you’re using. I’d pull all of that inline JavaScript that’s creating a search index and stick that into a .js file. Then you can load it in after the rest of the page has loaded to improve page performance.

This is exactly what I do with several of my themes.


#10

Okay, I will give it a try. Don’t have too much Jekyll experience, is it okay if I send you the branch and see if it’s okay?


#11

Just gave it a go, and I am completely lost…

I have duplicated your lunr search in js and includes, so do I just replace this:

{% include search-lunr.html %}

With this?

{% include lunr-search-scripts.html %}

Thanks!


#12

Jekyll experience isn’t really required. It’s more of a basic HTML thing. Essentially the theme developer placed a bunch of JavaScript in the page’s head, inline between <script></script> tags, which as @chuckhoupt noted probably isn’t a good idea.

As you get more posts it’s going to balloon in size and you really don’t want to jam all that post content on every page… inline.

What you want to do is take that include I linked to above, remove those <script></script> lines and place it in a .js file instead. Then you’ll link that into your layout, preferably after the content, near the closing </body> tag with something like this:

<script src="your-search-file.js"></script>

Or if this is all above you maybe file an issue with the theme developer and see if they’ll address it.


#13

I did it here: https://github.com/GiacomoLaw/blog/tree/lunrfix

Put hitting enter simply reloads the page.


#14

You’re close. You need to add blank YAML Front Matter to /assets/js/lunrsearchengine.js

Since that file has Liquid in it that’s not getting processed by Jekyll. If you add the following to the top of that file it should work.

---
layout: null
sitemap: false
---

#15

It worked, than you so much!