How to NOT load File and instead, load it locally

This is a “how to” question.

By using the code injection or by using the theme, can we dequeue / unset / remove the load of a file and instead, point to our own copy of the same file?

I’ve read through most of the documentation without finding any information on this. Can we use {{assets}} to do this?

I think you are pulling that dequeue stuff from WordPress. That is not what Ghost assets does nor am I aware of any function to do what you are describing. Which file are you trying to unload? These are normally theme powered and can be configured simply via editing the theme.

Yes, I am (taking that word / phrase from WordPress).
I’m looking into not loading the portal.min.js file, which is not loaded by the theme. At least not from what I can see / understand.

I downloaded a local copy of it (very annoying that they choose to use a CDN for that feature) and reviewed it. The idea is to change the link and the text of the “Publish with Ghost” button on the bottom left.

I’ve tried several CSS solutions and none of them work.

Theres been quite a few discussions about that loaded file (New in v4) recently. At this time it looks like it is required by the product and needed for Membership features. Maybe in a future release there will be the ability to inline it yourself instead of using a CDN. Or disable it if Members is disabled.

You can’t remove the ghost_head partial, because there goes your SEO/meta tags. You could probably build a CSP rule to block unpkg, but thats overkill.

Ok. Was thinking of making a JS file that blocks unpkg and then load the same file locally…?

Hey, did you find a solution ? I’m interested in it if you did :slight_smile:

Hi @Quentin_Lechasles,

Well, kind of. I went with editing a core file and instead of loading the file from the external source, I just changed the URL into my own domain and that way, load it from there.

It allows you to make whatever changes you like and yes, everything works fine. I’m running it that way on my site.

1 Like

If you want to load a different portal.min.js file you can do so by modifying your Ghost config.environment.json file.

The default config is:

"portal": {
        "url": "https://unpkg.com/@tryghost/portal@~1.1.0/umd/portal.min.js",
        "version": "~1.1.0"
    }

You can add this and change it, if you want to load locally or a forked version.

2 Likes

Ahh, even better. And doing so will not affect future updates / upgrades either?

I edited the core file (core, shared) and changed the URL. That caused upgrade issues from 4.1.2 to 4.2.0

If this is better or preferred way of doing it, I’ll fix my site asap.

Yes, this is the correct way to do it to prevent the problem with upgrading.

1 Like

Awesome, thanks for the feedback and information. Appreciate it. I’ll fix my site NOW :slight_smile:

@Hannah Please, can you answer something for me / shed some light on something for me?

#1: are there plans on adding support for link target (<a href="" target="") to the editor?
As of now, all links are direct as in, “happening in the same tab”. This means you loose your reader.

#2: are there any plans on adding additional settings for the accent color? It is very hard to find a color that works for all the different areas affected by the accent that works for both light and dark mode.

Thanks for your time.

How can we defer locally sourced portal.min.js in the config?