-3

I dont know whether it is possible looking for advice

if anyone have used wp-rocket they would know when page is served from cache it shows comment tag after that page is generated at hh/mm/ss

    <html>
    <head>
    <title> Site Title </title>
    </head>
    <body>
Body area
    </body>
    </html>

<!-- Like this -->

Same as in image

15
  • 2
    why? it does not like anyone would see it, or are you talking about server-side js? Commented Jul 4, 2020 at 7:16
  • 2
    there is a method document.createComment(); but may i know the purpose of injecting comments after the closing tag? Commented Jul 4, 2020 at 7:20
  • 1
    Shouldn't you do that on the backend (if at all) instead of in the browser? Commented Jul 4, 2020 at 7:29
  • 2
    You are mistaken if you think that using javascript within the page will modify the file itself stored on server. Why can't you just do it manually? Commented Jul 4, 2020 at 7:31
  • 2
    Only for the life of the page in browser. Each time you load the page it pulls the original file from the server. There is nothing you can do with javascript in the page to actually modify the file on the server. That would require being done by server side programming language Commented Jul 4, 2020 at 7:36

1 Answer 1

1

Working Code!! using jQuery after() method.

Observe the result after Inspect in Browser Developer Tools (F12)

$('html').after('<!-- Like this -->');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>

<head>
  <title> Site Title </title>
</head>

<body>
  Body area
</body>

</html>

Sign up to request clarification or add additional context in comments.

11 Comments

Wow! Amazing never crossed my mind
Nice! it works!
Is there a way to put line break with this? like </html> Break break <!-- Like this --> Break break
@Asad: For adding any break, we need insert <br> tag, which can't be added after </html> ending tag. If user tries to do so, it thows console / functional error. Thanks!
@solanki is it possible to replace </html> itself with 2 linebreaks ? like done with div inner html
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.