Problem with the default.hbs with is statement

hello, I’m developing a theme for my website and I would like to use specific javascript on my home page ( not index.hbs ) a landing page and I have this code in my default.hbs above ghost_head .

 {{#is "index"}}
    <script src="{{asset "built/index.js"}}" defer></script>
    {{ghost_head exclude="card_assets"}}
    {{else}}
    <script src="{{asset "js/page.js"}}" defer></script> 
    {{ghost_head}}
    {{/is}}

The code works nicely on the homepage but when I navigate to other pages the index.js still loads and the page.js does not. However when I reload the page it works just fine ??

I have also tried to create de specific default-home.hbs but somehow the index.js still shows up ! Is it a caching issue ?

BTW I use the ghost starter theme from github and npm run dev so there is a livereload.js code ( just saying if this could be related )

Any help would be appreciated if possible.

You may want to check for home, not index, as I think all collections are ‘index’

Getting a different result on reload is weird - possibly caching somewhere, or you’re reloading faster than rollup can rebuild, perhaps?

I assume you’re looking at the page source to see what’s loading?

Hello Cathy,

Thank you for taking the time to answer.

I think I might know where this is coming from inside the index.js there is swup.js and i’m no js expert but since it’s for page transition. Swup.js might be preloading the links on the page ?

But since this index.js comes into conflict in my post.hbs ( comments and lite-youtube.js ) are not loading on the first try only after reload I don’t get it !

I’ve tried to load the index.js directly into the homepage and removing the default but still the same problem

BTW @Cathy_Sarisky I got the exclude=“card_assets” from your blog ;) thanks for sharing that !!

1 Like

Hello again,

I have found a workaround I just add a data-no-swup to all links in the homepage and it works. Si it was definitely a swup.js problem.

Thanks Cathy