mrfdn.com – Jika kita punya file javascript yang berjalan normal tanpa menggunakan framework seperti Svelte, yang ingin dijalankan pada projekan Astro, secara normal untuk bisa menjalankannya kita akan menemui error:
document is not defined
Browser APIs are not available on the server.
If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a client:only directive to make the component exclusively run on the client.
See for more information.
Jadi untuk menjalankan script tersebut kita harus menempatkannya di dalam fungsi onMount() yang sudah ada sebagai bawaan Svelte.
Kode dasarnya seperti ini:
import { onMount } from 'svelte';onMount(() => { // Paste plain javascript di sini. // Code to run when the component is mounted});Fungsi onMount adalah untuk menjalankan script yang ada di dalamnya ketika sebuah component dipanggil.
Contoh cara menggunakan Svelte onMount pada projekan Astro#
- Buat sebuah komponen svelte contoh
MyComponent.svelte(pastikan penamaan komponen diawali dengan huruf kapital) lalu paste kode ini di dalamnya,
<script>import { onMount } from 'svelte';onMount(() => {function say() { const main = document.querySelector("#say"); main.innerHTML = "<p>Halo</p>"; }; say();});</script><div id="say"></div>- Pada komponen lain baik itu Astro maupun Svelte panggil dengan membuat div dengan id #say. Contoh buat komponen lain dengan nama
OtherComponent.astro, lalu tambahkan propclient:loaddi dalam tagnya supaya MyComponent bisa otomatis load.
---import MyComponent from "./MyComponent.svelte";---<MyComponet client:load/>- Pada layar akan mengeluarkan tulisan Halo.
Selesai.
Penjelasan lebih lanjut tentang onMount.
Semoga bermanfaat.
PakarPBN
A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.
In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.
The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

