Replies: 5 comments
-
Starting Next.js 11 :: vercel/next.js#14863 (comment) Can such similar feature be requested into SvelteKit? |
Beta Was this translation helpful? Give feedback.
-
Initialize your script in the root layout, using |
Beta Was this translation helpful? Give feedback.
-
is it worthy to have a <svelte:script
// a strategy to early load to insert in head before all other script, or lazy load at end of body;
strategy="beforeInteractive | afterInteractive | lazyOnload | worker | ..."
async
src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxx"
on:load={() => {
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-xxxxxx');
}}
/> or extend current <svelte:body
on:mouseenter={handleMouseenter}
on:mouseleave={handleMouseleave}
use:someAction
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxx"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-xxxxxx');
</script>
/> |
Beta Was this translation helpful? Give feedback.
-
open'ed issue #8495 #8495 (comment) and it's not resolved |
Beta Was this translation helpful? Give feedback.
-
@tx0c did you come up with anything for this you liked? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
have a piece of 3rd party script need to be placed at end of html body,
e.g. a piece of google analytics script;
it can be placed at end of
svelte:head
section, but there's a reason in some cases better to be at end ofbody
nothead
,another way is to put at before end of body in the
./src/app.html
template, but this would apply to all routes,but what if I want to put this script in some layouts only, not all HTML files, better to use a sub-group
(group)/+layout.svelte
;So wonder, inside any
*.svelte
, what is the best way to embed some script before end of body?I have looked at
svelte:body
but it is for some different purpose,https://svelte.dev/docs#template-syntax-svelte-body
I would wish the
svelte:body
can work with a slot?Not sure if this is a question to sveltekit or svelte?
Beta Was this translation helpful? Give feedback.
All reactions