Generally speaking, the first method should be your preferred way of referencing any resources that are part of your application. It is called a relative URI reference and it allows you to transfer your application to another domain-name without changing all the links.
You may even consider using relative paths such as
<img src="img/world.gif" />
... assuming that the HTML above appears at some place like http://www.example.com/myapp/main.html
That way you are also not tied to the /myapp path prefix and could easily move your application to /superapp without changing a thing.
Most application frameworks and templating systems have a way of reporting the root URI of the current application. In such cases it may be most convenient to use something like
<img src="$(APPROOT)/img/world.gif" />
... depending on what specific replacement/expansion mechanism your particular envrionment has. Here it is assumed that $(APPROOT) will be replaced with the absolute base URI of the current application.