Home

OnLoad

OnLoad refers to a trigger or handler that runs when a component, document, or interface has finished loading. It is used to perform initialization tasks that require all resources to be available, such as rendering data, attaching event handlers, or starting animations.

In web browsers, the onload event fires after the entire document and all dependent resources have loaded.

Best practices encourage using DOMContentLoaded or similar events to initialize UI quickly, reserving onload for tasks

Beyond the browser, OnLoad is used in various GUI frameworks as a conventional name for initialization code

See also DOMContentLoaded, page load, ready event.

It
can
be
wired
either
with
the
onload
attribute
in
HTML,
or
by
registering
a
listener
for
the
load
event
in
JavaScript
(for
example
window.addEventListener('load',
...)).
Because
onload
fires
after
images,
scripts,
and
subframes
have
loaded,
it
often
occurs
later
than
the
DOMContentLoaded
event,
which
signals
that
the
document
structure
is
ready
but
not
necessarily
all
resources.
that
genuinely
require
all
resources.
Avoid
heavy
work
in
onload,
and
consider
async
loading
and
deferred
resources
to
reduce
perceived
load
time.
that
runs
when
a
component
is
displayed.
In
Microsoft
.NET,
for
example,
a
Form
or
Page
may
expose
a
Load
or
OnLoad
method
that
developers
override
to
set
up
data
and
state.