mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 12:03:25 -04:00
Merge branch 'speculationrules-p' into 'main'
(perf) start using speculationrules API See merge request PronounsPage/PronounsPage!586
This commit is contained in:
commit
64f2832024
@ -8,7 +8,7 @@ import useDark from '~/composables/useDark.ts';
|
||||
import useDialogue from '~/composables/useDialogue.ts';
|
||||
import { longtimeCookieSetting } from '~/src/cookieSettings.ts';
|
||||
import { LoadScriptError } from '~/src/errors.ts';
|
||||
import { newDate } from '~/src/helpers.ts';
|
||||
import { executeUnlessPrerendering, newDate } from '~/src/helpers.ts';
|
||||
import { useMainStore } from '~/store/index.ts';
|
||||
|
||||
// no need to be super secure, just a sign that the page is not public
|
||||
@ -42,7 +42,7 @@ const checkTesterPassword = (): void => {
|
||||
testerPasswordCookie.value = testerPassword.value;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(executeUnlessPrerendering(() => {
|
||||
sorter();
|
||||
|
||||
confirmAge();
|
||||
@ -67,7 +67,7 @@ onMounted(() => {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
const dialogue = useDialogue();
|
||||
const confirmAge = async (): Promise<void> => {
|
||||
|
23
plugins/speculationrules.ts
Normal file
23
plugins/speculationrules.ts
Normal file
@ -0,0 +1,23 @@
|
||||
export default defineNuxtPlugin(() => {
|
||||
useHead({
|
||||
script: [
|
||||
{
|
||||
type: 'speculationrules',
|
||||
innerHTML: JSON.stringify({
|
||||
prerender: [
|
||||
{
|
||||
where: {
|
||||
and: [
|
||||
{ href_matches: '/*' },
|
||||
{ not: { selector_matches: '.no-prerender' } },
|
||||
{ not: { selector_matches: '[rel~=nofollow]' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
eagerness: 'moderate',
|
||||
}),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
@ -2,6 +2,8 @@ import * as Sentry from '@sentry/vue';
|
||||
import { defineNuxtPlugin, useRouter } from 'nuxt/app';
|
||||
import type { RouteLocationNormalized } from 'vue-router';
|
||||
|
||||
import { executeUnlessPrerendering } from '~/src/helpers.ts';
|
||||
|
||||
const USER_AT = /^\/@.+/;
|
||||
const USER_SUBPAGE = /^\/(u|card)\/.*/;
|
||||
|
||||
@ -21,6 +23,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
const router = useRouter();
|
||||
|
||||
const trackPageview = (route: RouteLocationNormalized): void => {
|
||||
executeUnlessPrerendering(() => {
|
||||
try {
|
||||
const toUrl = normalizeUrl(new URL(route.fullPath, window.location.href));
|
||||
console.debug('[analytics] tracking page view:', toUrl.toString());
|
||||
@ -32,6 +35,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
} catch (error) {
|
||||
Sentry.captureException(error);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
// Track the initial page load
|
||||
|
@ -562,3 +562,13 @@ export const filterObjectKeys = <T extends Record<string, any>, K extends keyof
|
||||
return filteredObj;
|
||||
}, {} as Pick<T, K>);
|
||||
};
|
||||
|
||||
export const executeUnlessPrerendering = (fn: () => void): (() => void) => {
|
||||
return () => {
|
||||
if ((document as any).prerendering) {
|
||||
document.addEventListener('prerenderingchange', fn, { once: true });
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user