Sending custom http-equiv meta tags for only certain .md files in /content

Any ideas how to do this?

The problem I am facing is this:

https://psychedelicsdaily.com/radio/ seems to cache audio stream. I want to send the following headers.

Would I simply check in the head.html partial to see if the current page is a certain link or content file, and if so, send custom headers?

I want the rest of the site to have caching but the one page to not have it by sending:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 9999 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

http://radio.psychedelicsdaily.com/ is hosting a standalone copy of my Radio Player, to be used for my mobile app (mobile app using Cordova/Phonegagp to display this in an iframe) and there it functions beautifully w/o caching.

Caching seems to mess up some radio stream caching.

Now, I’m unsure how to go about this. I don’t want to send custom headers in nginx or any other http for the whole domain. I know client side http meta equiv are not that reliable depending on browser, etc. but I’d like to keep it client side.

Any ideas how to do this in Hugo?

{{ if eq .URL "/radio" }}
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 9999 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />
{{end}}

I have tried the above and many other variations, but they don’t work. I’m unsure how to detect when it’s /content/radio.md and then send those headers

And no luck here either.

{{ if eq .File.Path "/content/radio.md" }}

I don’t think that’s the way to go. These meta tags are not valid in html5. They used to be in html4.

EDIT
You should send caching instructions as real HTTP headers, provided you have admin privileges on the server you use to host your site.

content/radio.md front matter

headers='<meta http-equiv=\"cache-control\" content=\"max-age=0\" /><meta http-equiv=\"cache-control\" content=\"no-cache, no-store, must-revalidate\" /><meta http-equiv=\"expires\" content=\"0\" /><meta http-equiv=\"expires\" content=\"Tue, 01 Jan 9999 1:00:00 GMT\" /><meta http-equiv=\"pragma\" content=\"no-cache\" />'
+++

head section

{{ .Params.headers }}

And this is how it’s rendered in page source:

&lt;meta http-equiv=\&#34;cache-control\&#34; content=\&#34;max-age=0\&#34; /&gt;&lt;meta http-equiv=\&#34;cache-control\&#34; content=\&#34;no-cache, no-store, must-revalidate\&#34; /&gt;&lt;meta http-equiv=\&#34;expires\&#34; content=\&#34;0\&#34; /&gt;&lt;meta http-equiv=\&#34;expires\&#34; content=\&#34;Tue, 01 Jan 9999 1:00:00 GMT\&#34; /&gt;&lt;meta http-equiv=\&#34;pragma\&#34; content=\&#34;no-cache\&#34; /&gt;

Yeah, I guess that’s a better idea.

    location ~*  \.(mp3|mp4|m4a|ogg)$ {
        expires off;  

I wonder if I need to do anything else.

1 Like

Also, why does it render like this? How can I echo the contents of the .Params.headers frontmatter in the head.html partial and not have it turn into html entities and special chars?

I think you need to use the safeHTML function, like this:

{{ .Params.headers | safeHTML }}
1 Like