Pode.Web icon indicating copy to clipboard operation
Pode.Web copied to clipboard

Adding custom javascript snippets or importing files in the html HEAD section

Open idanmashaal opened this issue 2 years ago • 5 comments

Question

Hi, Currently when using Import-PodeWebJavaScript with the location of a file, lets say '/assets/js/custom_script.js' the script will be called at the bottom of the rendered html.

Some scripts require to be run on the head, either by importing the files or by embedding the script tag snippet. An example for this would be analytics, but of course not limited to this.

How would I achieve calling a custom script from the head tag and instead of the end of the rendered html? I searched open and closed issues, as well as reviewed the code and documentation but it's not clear to me if this is possible without modifying the head.pode file which I'm not sure is a good idea (what happens upon upgrades, etc).

Thanks, Idan.

idanmashaal avatar Jun 11 '23 14:06 idanmashaal

Hi @idanmashaal,

You're correct, at the moment this isn't supported - at least, without editing the head.pode file any way, but yes this will be lost on an upgrade.

I can look at adding in support for toggling between where the custom JS files are loaded :)

Badgerati avatar Jun 12 '23 22:06 Badgerati

Thanks @Badgerati - that would be a great feature enhancement with two new flags to the Import-PodeWebJavaScript. -Head ==> will import the script in the

html tag -Async ==> will add the "async" directive And we will be able to use any combination of it.

Thoughts?

idanmashaal avatar Jun 12 '23 22:06 idanmashaal

I hadn't even thought about async! For custom scripts that shouldn't be much of an issue, so an Async switch would work. The other will likely be a Set parameter allowing either Head or Body to be passed - say "-Location", with Body as default.

Badgerati avatar Jun 12 '23 22:06 Badgerati

That sounds perfect! And if the parameters are not set, the behavior will be as it is now ?

On Tue, 13 Jun 2023 at 1:10 Matthew Kelly @.***> wrote:

I hadn't even thought about async! For custom scripts that shouldn't be much of an issue, so an Async switch would work. The other will likely be a Set parameter allowing either Head or Body to be passed - say "-Location", with Body as default.

— Reply to this email directly, view it on GitHub https://github.com/Badgerati/Pode.Web/issues/497#issuecomment-1588176919, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC4BOZLNBCTLTMTALGZ7ZDXK6HV3ANCNFSM6AAAAAAZCLVF7M . You are receiving this because you were mentioned.Message ID: @.***>

idanmashaal avatar Jun 12 '23 22:06 idanmashaal

Yes, the default location would be "body", so would still work as it does currently if none of the new parameters are supplied.

Badgerati avatar Jun 14 '23 22:06 Badgerati