Hey theme devs! I 'fixed' {{ghost_head}}

In case you missed it in the release notes today, here’s the patch I’ve wanted for a long time that solves a whole bunch of “we can’t change it because its in ghost_head” problems.

Among (many, many) other things, it’s a way to load a custom version of the portal on Ghost Pro.

Many thanks to @vikaspotluri123 for help with broken tests, to multiple members of the Ghost dev team for nudging me along when I got stuck, and especially to @hannah for helping me work out what the options should (and shouldn’t) be.

p.s. Wanna know the really sad thing? My own site is a couple minor versions back and stuck there until I make some time to dig into the problem, so I can’t actually use it! Yet…

16 Likes

Having read about your journey with {{ghost_head}} I got really excited today when I saw your commit in the release notes.

Really great job on this – love how modular it is. Makes me want to dive a bit into theme development again, just to be able to use it.

Thanks for the “fixing” it, Cathy :blush:

3 Likes

I mean, really, I set it up so that you can use it to absolutely BREAK things, but… :)

2 Likes

:partying_face: :partying_face: Great job, Cathy!

2 Likes

This is great, ability to exclude announcement bar and comments, and link assets locally. Thank you!

2 Likes

Awesome work, Cathy! I can’t wait to try it with custom themes. It’s going to solve a lot of issues. Thank you very much! :partying_face:

2 Likes

I’m super interested to hear how you use it and where it falls short. I didn’t realize that I needed {{content_api_url}} until I went to write the examples, and there might be other needs. Examples with use cases would be a good way to advocate for additions or new helpers.

(And yes, content_api_url and _key are also available now!)

2 Likes

I see the exclude attributes are documented on your blog. When will they documented officially? I would expect a mention or documentation here.

2 Likes

The stuff on my blog is a copy-paste of a documentation draft. :slight_smile: It’s coming, but I can’t PR the docs, so I’m not sure how soon. :)

2 Likes

And @markstos , I tried to add in suppression of the generator bit, and lost that argument. (In fairness, Hannah was right that it didn’t seem like something a theme should control.)

I suspect that a PR that added an argument in config.<env>.json would probably get merged. My first write of the ghost_head changes actually included it and took a config.json argument (not an argument to ghost_head), so it should be possible to resurrect some of that work, just for the generator line. This commit shows what I cut /out/ to switch strategies. Feel free to grab anything useful there.
updated design (inline exclude) and updated tests · TryGhost/Ghost@4add875 · GitHub

[Unless someone funds it, I’m not going to get to it any time soon, so if you want it, please put in the PR!]

2 Likes

@Cathy_Sarisky This is great!

I have often wanted to get rid of search/portal code for sites that don’t need it, to get better performance and pageespeed scores. Now I can — without doing anything hacky!

2 Likes

Excellent work. Thank you!

1 Like

@Cathy_Sarisky You’re amazing, thank you for being part of this community and sharing all your awesome work!

1 Like

@Cathy_Sarisky Great Job! Congratulations this feature was required a very long time ago :clap::clap:

A minor question, is there any plan to exclude Stripe script as well?, I saw some new codes in the commit, but it seems is not implemented yet.

Best,

I wrote some code to suppress Stripe in an early draft that didn’t survive the discussion/rewrites/refinements/improvements necessary to get it merged.

As I understand it, the Stripe script only loads if Stripe is actually configured. (ghost_head checks the settings cache for paid_members_enabled). As a result, I didn’t have a great argument or use case for excluding the script, but if you have one, please share it! I would be happy to take an argument for suppressing Stripe back to the dev team.

We did have some discussion about how it could probably be switched to ‘defer’ instead of async, that I don’t think has gotten any follow-up yet. (I at least haven’t done anything with it.)

If you’re seeing Stripe load when it should not (when not configured or no paid memberships available), please provide some details! That would be a bug. :)

I think there’s an interesting discussion to be had about how Ghost could offer better support (tiers, etc) for sites that aren’t connected to Stripe, but that probably needs a separate post over in the ideas forum, rather than here.

1 Like

Hey! @Cathy_Sarisky thanks a lot for your detailed explanation! really appreciate it.

And yes, basically I’m optimizing as much as possible our themes, so the script is generating a medium delay on the website: Screenshot by Lightshot so i’m moving all possible scripts from “head” to a more optimized location and with different parameters as “defer”.

It is pretty common on Custom Theme, that we as authors create a dedicated “membership” page, so the portal buttons and other functionalities can be safely omitted and optimized.

Anyway, I just did some quick tests and got very consistent and good results with this change, thank you again for this contribution :+1::+1: it was really needed.

Best,

1 Like