Skip to content

Print a warning when LiveReload fails to inject its code  #10105

@anakinsleftleg

Description

@anakinsleftleg

There are more than a few posts on the Hugo Discourse over the years through recent times of users having LiveReload not work in hugo server. The cause seems to be their templates missing either the <head> or the <body> tags. As @davidsneighbour has pointed out, HTML5 doesn't require these tags (or the <html> tag).

I feel it would make LiveReload more foolproof if the function would inject those html tags in order to inject the LiveReload script if they are missing, instead of failing silently without the user knowing why it isn't working. Or at least a WARNING in the console saying that those tags were not found and so LiveReload was not enabled. Maybe both. The first covers the fact that it'll just work for any user regardless of theme or experience and result in a good user experience (not having anything silently not working as expected) and the second teaches users that they are missing typical tags

I experienced this very thing today and was about to make a post on Discourse about it but was able to parse through the posts and find the issue. The problem is if you "Inspect Page" with DevTools, those missing html tags are injected by DevTools and so it looks like they are there, but you have to go to "View Source" to see that in fact they don't exist in the html.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions