-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

Asad
  • 3
  • 4
  • 2
    why? it does not like anyone would see it, or are you talking about server-side js? – apple apple Jul 04 '20 at 07:16
  • 2
    there is a method document.createComment(); but may i know the purpose of injecting comments after the closing tag? – Santa Jul 04 '20 at 07:20
  • for showing when i updated my page last time – Asad Jul 04 '20 at 07:27
  • 1
    Shouldn't you do that on the backend (if at all) instead of in the browser? – str Jul 04 '20 at 07: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? – charlietfl Jul 04 '20 at 07:31
  • I think i saw somewhere it is bookmarked that we can update using a js onload it will modify the html – Asad Jul 04 '20 at 07:34
  • @str i am newbie dont know that much so just doing a shortcut – Asad Jul 04 '20 at 07:35
  • 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 – charlietfl Jul 04 '20 at 07:36
  • @charlietfl i knew it, but i think it serves my need for now – Asad Jul 04 '20 at 07:39
  • @charlietfl you closed it saying duplicate but all those questions are talking about inner html not outer – Asad Jul 04 '20 at 07:54
  • @Asad That is not true. For example the last question is clearly about an element (e.g. a comment node) *after* another element. – str Jul 04 '20 at 07:55
  • @str i saw them when posting, none of them serves my need, they are not working outside

    - fine for inside

    – Asad Jul 04 '20 at 08:06
  • @Asad Yes it *does* work outside of the `html` element. – str Jul 04 '20 at 08:07
  • @str please check the answer by @ Solanki below which serves my need – Asad Jul 04 '20 at 08:08
  • @str i tried those but they didnt worked for me i posted it afterwards – Asad Jul 04 '20 at 08:10

1 Answers1

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>
solanki...
  • 4,982
  • 2
  • 27
  • 29