Skip to content

Commit

Permalink
Side load GVL translations to reduce payload size
Browse files Browse the repository at this point in the history
  • Loading branch information
gilluminate committed Jul 9, 2024
1 parent 072ac20 commit f901d27
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions clients/fides-js/src/lib/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
updateCookieFromNoticePreferences,
} from "./cookie";
import {
ComponentType,
ConsentMechanism,
ConsentMethod,
FidesConfig,
Expand Down Expand Up @@ -430,6 +431,26 @@ export const initialize = async ({
fides.cookie = updatedCookie;

if (shouldInitOverlay) {
if (
fidesRegionString &&
fides.experience.experience_config?.component ===
ComponentType.TCF_OVERLAY
) {
debugLog(options.debug, "Fetching GVL translations...");
const { gvl_translations: gvlt } = await fetchExperience(
fidesRegionString,
options.fidesApiUrl,
options.debug,
options.apiOptions,
undefined,
true
);

// eslint-disable-next-line no-param-reassign
fides.experience.gvl_translations = gvlt;
debugLog(options.debug, "GVL translations loaded", gvlt);
}

// Initialize the i18n singleton before we render the overlay
const i18n = setupI18n();
initializeI18n(
Expand Down
10 changes: 9 additions & 1 deletion clients/fides-js/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const fetchExperience = async (
fidesApiUrl: string,
debug: boolean,
apiOptions?: FidesApiOptions | null,
propertyId?: string | null
propertyId?: string | null,
includeGvlTranslations?: boolean
): Promise<PrivacyExperience | EmptyExperience> => {
debugLog(debug, `Fetching experience in location: ${userLocationString}`);
if (apiOptions?.getPrivacyExperienceFn) {
Expand Down Expand Up @@ -87,6 +88,13 @@ export const fetchExperience = async (
// that have no relevant experiences
const experience = (body.items && body.items[0]) ?? {};
debugLog(debug, "Recieved experience response from Fides API");
if (
experience.experience_config?.component === ComponentType.TCF_OVERLAY &&
!includeGvlTranslations
) {
// Remove GVL translations from experience to reduce payload size
experience.gvl_translations = undefined;
}
return experience;
} catch (e) {
debugLog(
Expand Down

0 comments on commit f901d27

Please sign in to comment.