@@ -1027,30 +1027,31 @@ document.addEventListener("DOMContentLoaded", async () => {
1027
1027
const changelogTapThreshold = 5 ;
1028
1028
const changelogTapTimeout = 1000 ;
1029
1029
let changelogTapTimer : NodeJS . Timeout ;
1030
+ let changelogFetchSuccess = false ;
1031
+ let changelogHTML : string ;
1030
1032
1031
1033
const changelogLink = document . querySelector ( "#changelog-link" ) as HTMLAnchorElement ;
1032
1034
changelogLink . addEventListener ( "click" , async ( e ) => {
1033
1035
e . preventDefault ( ) ;
1034
- // Fetch changelog
1035
- // TODO: Cache it
1036
- let changelog : string ;
1037
- let changelogFetchSuccess = false ;
1038
- try {
1039
- const res = await fetch ( "CHANGELOG.html" ) ;
1040
- if ( res . status !== 200 ) {
1041
- console . error ( "Could not fetch changelog:" , res . statusText ) ;
1042
- changelog = `<p class="changelog-error">Could not retrieve changelog.</p>` ;
1043
- } else {
1044
- changelog = await res . text ( ) ;
1045
- changelogFetchSuccess = true ;
1036
+ // Fetch changelog (or use cached version if already fetched)
1037
+ if ( ! changelogFetchSuccess ) {
1038
+ try {
1039
+ const res = await fetch ( "CHANGELOG.html" ) ;
1040
+ if ( res . status !== 200 ) {
1041
+ console . error ( "Could not fetch changelog:" , res . statusText ) ;
1042
+ changelogHTML = `<p class="changelog-error">Could not retrieve changelog.</p>` ;
1043
+ } else {
1044
+ changelogHTML = await res . text ( ) ;
1045
+ changelogFetchSuccess = true ;
1046
+ }
1047
+ } catch ( e ) {
1048
+ console . error ( "Could not fetch changelog:" , e ) ;
1049
+ changelogHTML = `<p class="changelog-error">Could not retrieve changelog.</p>` ;
1046
1050
}
1047
- } catch ( e ) {
1048
- console . error ( "Could not fetch changelog:" , e ) ;
1049
- changelog = `<p class="changelog-error">Could not retrieve changelog.</p>` ;
1050
1051
}
1051
1052
const dialogElem = createDialogContentFromTemplate ( "#changelog-content" ) ;
1052
1053
const changelogElem = dialogElem . querySelector ( "#changelog-text" ) as HTMLElement ;
1053
- changelogElem . innerHTML = changelog ;
1054
+ changelogElem . innerHTML = changelogHTML ;
1054
1055
if ( changelogFetchSuccess ) {
1055
1056
// Capitalize title
1056
1057
( changelogElem . children . item ( 0 ) as HTMLElement ) . style . textTransform = "uppercase" ;
0 commit comments