Skip to content

Commit

Permalink
feat(head): added api dns prefetch and preconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Jun 20, 2024
1 parent 0e3b823 commit 9c45182
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/lib/components/preconnect/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import { createApiUrl } from '$lib/functions/api/createurl';
const apiUrlStr = createApiUrl().toString().replace(/\/$/, '');
</script>

<svelte:head>
<link rel="dns-prefetch" href={apiUrlStr} crossorigin="anonymous" />
<link rel="preconnect" href={apiUrlStr} crossorigin="anonymous" />
</svelte:head>
2 changes: 1 addition & 1 deletion src/lib/components/searchbox/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
function handleSubmit(e) {
if (query === '') {
e.preventDefault();
} else {
} else if (!loading) {
loading = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/functions/api/createurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { env } from '$env/dynamic/public';

/**
* Create an API URL
* @param {string} path
* @param {string} [path]
* @param {URLSearchParams} [params]
* @returns {URL}
*/
Expand All @@ -14,7 +14,7 @@ export function createApiUrl(path, params) {
throw error(500, 'PUBLIC_API_URI env is not defined');
}

const apiUrl = (apiUri.endsWith('/') ? apiUri : apiUri + '/') + path;
const apiUrl = (apiUri.endsWith('/') ? apiUri : apiUri + '/') + (path ?? '');
const urll = new URL(apiUrl);

if (params) {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script>
import '../app.css';
import Preconnect from '$lib/components/preconnect/main.svelte';
import ThemeToggle from '$lib/components/themetoggle/main.svelte';
import Footer from '$lib/components/footer/main.svelte';
</script>

<Preconnect />

<ThemeToggle />

<main class="min-h-[90lvh]">
Expand Down

0 comments on commit 9c45182

Please sign in to comment.