-1

I want to use absolute urls because I create my project on mvc pattern and for maintain purpose I wrote something like this on images: define(Base_url,www.domain.com);echo Base_url."image url or scrupt url";

I want to learn this are in better way? is it fast to write absolute url? I want to achieve max speed on website

Kalu Singh Rao
  • 1,671
  • 1
  • 16
  • 21
Alex
  • 29
  • 5

1 Answers1

0

I don't think it's going to hit performance issue but illumine a correct path. Since common MVC frameworks I knew would likely separate their public file such assets you mentioned. They are likely going to confuse you in order to fetch the assets according to its prettify-URL's rule. Then comes a const define or any global static method/function to help you grab the correct URL. To help you also to avoid simple mistake like this (notice the /)

<img src="images/image.jpg">
<img src="/images/image.jpg">

You can always cache it too if you still worry of it existance, since it's static -- surely applicable.

So, if you already get the correct URL/path each time you're going to display your assets without constant Base_url, then just don't write it down.

If you aware of performance, it's better to use const language construct, as it is defined in compile time. Or if you're using APC, you can also define it with apc_define_constants to perform built in opcode caching by APC.

Community
  • 1
  • 1
Chay22
  • 2,834
  • 2
  • 17
  • 25
  • My question is actually different,I want to learn which one is more better for speed Absolute urls or normal?Ok I actualy doesnt use mvc framework I use my own and I collect my images on public folder as you mentioned,Are there way that is more better write that kind of urls on images?You said cache but I want to get first time image load speed.For example www.mydomain/public/images vs /images? which one is better?Are there way dont write const Base_URL? – Alex Jun 25 '16 at 15:17
  • The latter reason i explained should be expanded, but yeah.. hate my grammar. I should mention it before on why don't I explain your expected answer, because you (should) already knew it. Existence vs Non-existence. Who wins? Running a marathon vs sleeping. Which more energy consuming? Adding a single char of var will ofc gain cost for compiling. Furthermore, it's a constant `define`, which known as slower way to define a const since it defined at runtime. Its also applied for HTML, as people are always going to [minify it, but can't](http://stackoverflow.com/q/2359484/5816907) – Chay22 Jun 25 '16 at 16:45
  • Actually I can guests that short url is better but I want to learn that are there way to write images' urls without this way and with short urls? – Alex Jun 25 '16 at 17:56
  • I answered it indirectly on my post, if you can use the "normal" one, go for it. And for, _without this way and with short urls?_, it made me wanna ask a question: are you looking for a way to shorten the url? (this question is based of my last comment about "minifying HTML"). If you are, `.htaccess` can lead you to the right track. Even create [`symlink`](http://php.net/manual/en/function.symlink.php) might do too. – Chay22 Jun 25 '16 at 18:30