Laravel's URL::to() vs URL::asset()

April 28, 2014

Short answer: No, not really.

You want to have the following code:

<script src="js/bootstrap.js"></script>

Now you can achieve this using blade syntax:

// using URL::to()
<script src="{{ URL::to('js/bootstrap.js') }}"></script>

// using URL::asset()
<script src="{{ URL::asset('js/bootstrap.js') }}"></script>


The method is implemented like this:

Laravel URL::to()


The method is implemented like this:

Laravel URL::asset()


Both methods get the job done.

  • URL::to() additionally encodes the segments of the passed url with rawurlencode
  • URL::asset() removes index.php from the path (which shouldn’t be in first place)

So you get more utility by using URL::to(), but also takes longer to execute (approx. 25% more than URL::asset()). But it’s strongly neglectible, since calling 100 times URL::to() takes 0.003523 ms.


If you’re using blade, you can use the following to easily output style and script tags.

{{ HTML::script('js/bootstrap.js') }}
{{ HTML::style('css/bootstrap.min.css') }}

Or using any of Asset Management packages like orchestra/asset.

Simon Wicki

Simon Wicki is a Frontend Developer in Berlin. Passionate and fluent in Vue, Angular, React and Ionic. I love Hybrid Apps and books.

Twitter Follow @zwacky