Reputation: 1496
My questions refers to base_url(), which is a helper function of codeigniter. The idea is that it grabs the base_url of my application and allows me to echo it anywhere on any of my view pages.
Below is an example of where I'd use base_url().
<script type="text/javascript" language="javascript" src="<?php echo base_url(); ?>assets/js/jquery.js"></script>
I sometimes call it several times in a DOM load and was wondering if it would be a good idea to store it into a php variable, rather than call the base_url fuynction each time. Like so:
<?php
$this->load->helper('url');
$base_url = base_url(); // Set to variable, so we don't method call each time
?>
<script type="text/javascript" language="javascript" src="<?php echo $base_url; ?>assets/js/jquery.js"></script>
I know this is a rather novice question, but I've been pretty OCD concerning optimization and am wondering if this addition of code would be worth its weight. I would have to add the defining of variable twice, as I use base_url() in both my head and body. Thanks for any help.
Upvotes: 1
Views: 456
Reputation: 140228
From performance point of view it doesn't matter either way. Do whatever makes your code easier to read/maintain. Do not place it in a session though.
As a side note, you should not use PHP in the first place if you are concerned about micro optimizations as it is one of the slowest things out there when it comes to raw processing power.
Upvotes: 1