3 ms·
© <span id="js-copyright-year">2023</span> My Product <script>document.getElementById('js-copyright-year').innerHTML = new Date().getFullYear();</script>
by benbristow 4y ago
© <span id="js-copyright-year">2023</span> My Product
<script>document.getElementById('js-copyright-year').innerHTML = new Date().getFullYear();</script>
Job's a good'un - if the user has JS disabled then they'll just see the year published as a fallback, otherwise it'll show 2024 when the new year rolls in.
If using a templating engine or some SPA framework/library like React then just dynamically substitute there instead or similar in server-side rendered code.
- iudqnolq 4y agoIANAL, but showing different years to different users vibely seems like a bad idea, especially based on something the user can pick. If it did matter then you might as well just show the default date, cause any adversary could pick to be shown it, no?
- benbristow 4y agoYou can update the fallback manually but at least you're somewhat covered until you do so.