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

**URL:** <https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650>\
**Category:** Help\
**Created:** [February 19, 2019, 1:36pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650 "2019-02-19T13:36:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 19, 2019, 1:36pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/1 "2019-02-19T13:36:19Z")

</div>

Hi all,

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

> **[Save time with .bat files](https://giacomolaw.me/blog/2019/02/cmd-everywhere/)**
>
> How to run .bat files from anywhere on Windows CMD like a command.

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

Thanks

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [February 19, 2019, 3:14pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/2 "2019-02-19T15:14:48Z")

</div>

Looks like it is data for [Lunr Search](https://lunrjs.com). Possibly part of the theme or custom layout?

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 19, 2019, 3:25pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/3 "2019-02-19T15:25:28Z")

</div>

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

Thanks

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [February 19, 2019, 4:20pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/4 "2019-02-19T16:20:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 19, 2019, 5:37pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/5 "2019-02-19T17:37:35Z")

</div>

Will do, thank you very much!

---

<div class="post-metadata">

**Author:** ![pabloduo](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pabloduo](https://talk.jekyllrb.com/u/pabloduo)\
**Post date:** [February 20, 2019, 4:33am UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/6 "2019-02-20T04:33:29Z")

</div>

@DipperDolphin, I have built something interesting based on [jekyll\_pages\_api\_search](https://rubygems.org/gems/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](https://pabloduo.com)

_Search is available on any page:_

 ![blog_search](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/2X/f/f672f1af4e465ae1d0d4ed10dd76c5eb17d5c0a0.png)

_Entering search query:_

 ![search_query](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/2X/8/8ee90766405ed689711e28269cc7ffc6391aeff0.png)

_Rendering search results:_

 ![search_results](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/2X/7/7af3737255efaee31bbbb7f1169f78eb43978978.png)

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 9:05am UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/7 "2019-02-20T09:05:49Z")

</div>

Looks interesting. I am actually using this theme: [https://github.com/wowthemesnet/mediumish-theme-jekyll](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 😃

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!

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 8:15pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/8 "2019-02-20T20:15:05Z")

</div>

Anyone have any idea how to fix this?

Thanks

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [February 20, 2019, 8:33pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/9 "2019-02-20T20:33:39Z")

</div>

You need to modify the theme you’re using. I’d pull all of that [inline JavaScript](https://github.com/wowthemesnet/mediumish-theme-jekyll/blob/master/_includes/search-lunr.html#L3-L107) 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](https://github.com/mmistakes/so-simple-theme/blob/master/assets/js/search-data.js).

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 8:34pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/10 "2019-02-20T20:34:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 8:38pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/11 "2019-02-20T20:38:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [February 20, 2019, 8:43pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/12 "2019-02-20T20:43:21Z")

</div>

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:

```auto
<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.

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 8:50pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/13 "2019-02-20T20:50:58Z")

</div>

I did it here: [https://github.com/GiacomoLaw/blog/tree/lunrfix](https://github.com/GiacomoLaw/blog/tree/lunrfix)

Put hitting enter simply reloads the page.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [February 20, 2019, 9:04pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/14 "2019-02-20T21:04:50Z")

</div>

You’re close. You need to add blank YAML Front Matter to [/assets/js/lunrsearchengine.js](https://github.com/GiacomoLaw/blog/blob/f30ac72b5ee446ec28264f09e4655c98734ad52a/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.

```auto
---
layout: null
sitemap: false
---

```

---

<div class="post-metadata">

**Author:** ![DipperDolphin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dipperdolphin/32/1549_2.png) [@DipperDolphin](https://talk.jekyllrb.com/u/DipperDolphin)\
**Post date:** [February 20, 2019, 9:08pm UTC](https://talk.jekyllrb.com/t/whats-with-all-the-json-at-the-top-of-my-posts/2650/15 "2019-02-20T21:08:17Z")

</div>

It worked, than you so much!
