Welcome Guest, Not a member yet? Register   Sign In
Relative link to CSS
#21

[eluser]tokyotech[/eluser]
[quote author="ntheorist" date="1247275612"]one other note, i prefer not to store css/js files within my system folder. I get a bit uneasy planting links anywhere that lead to system files, really.[/quote]

CSS and JS files can easily be seen with Firefox's Firebug extension. An htaccess protection will not help from someone jacking your files.

I've asked before on other web forums and there is just no way to protect client side files. Or are you speaking of someone editing your files? I have no experience in that kind of hacking.
#22

[eluser]cahva[/eluser]
A little tip for your develpment on localhost and online.. You dont have to set anything after going live when you set your base_url in config like this:
Code:
if ($_SERVER['SERVER_NAME'] == 'localhost')
{
    $config['base_url']    = "http://localhost/yourproject/";
}
else
{
    $config['base_url']    = "http://www.yourrealdomain.com/";
}

I myself dont want to use full urls everywhere because it creates http request on every load and for page with lots of images, styles, js etc. it will slow down the site. So if you want to use absolute url path on the server, you can modify your config like this:
Code:
if ($_SERVER['SERVER_NAME'] == 'localhost')
{
    $config['base_url']    = "http://localhost/yourproject/";
    define('ABS_URL','/yourproject/');
}
else
{
    $config['base_url']    = "http://www.yourrealdomain.com/";
    define('ABS_URL','/');
}

And as before mentioned, move your css and other assets outside of codeigniter directory. Much cleaner that way.

So for example if you've copied your master.css to "styles" folder in your project root, you could point your css like this:
Code:
<link href="<?php echo ABS_URL ?>styles/master.css" rel="stylesheet" type="text/css" />;

And because we setup config.php that way, that would work localhost and online no problemo Smile
#23

[eluser]Chad Fulton[/eluser]
[quote author="cahva" date="1247278804"]
I myself dont want to use full urls everywhere because it creates http request on every load and for page with lots of images, styles, js etc. it will slow down the site.
[/quote]

I'm not sure exactly what your meaning is here, but if you're suggesting that having a relative url (i.e. /styles/master.css) versus a full url (i.e. http://www.example/com/styles/master.css) affects performance, I believe that you are incorrect.

Reducing the number of HTTP requests is indeed crucial in optimizing website performance, but that can only be done by combining files and making sure that caching is working.

Furthermore, browsers convert all urls to full urls before checking cache / making http requests for the associated files. You can't get around http requests by using relative urls.

Check out this page for good info on optimizing.
#24

[eluser]tokyotech[/eluser]
One last question, how are you guys loading the URL helper in a view? I see you told me to use the base_url() function in the view. I don't think $this->load->helper('url') will work since the view is not a class, so $this is undefined.
#25

[eluser]cahva[/eluser]
Well it was true sometime ago. Maybe browsers are better these days and not do a lookup on every url in the page. However, as you put up that link to that optimize page, would'nt using relative paths actually optimize the page already as in page size? Smile
#26

[eluser]cahva[/eluser]
[quote author="tokyotech" date="1247282567"]One last question, how are you guys loading the URL helper in a view? I see you told me to use the base_url() function in the view. I don't think $this->load->helper('url') will work since the view is not a class, so $this is undefined.[/quote]
No not in view. Views are loaded in the controller so you either put it in the controller calling the view or autoload it url helper. Its so used helper its better to just add it to autoload.
#27

[eluser]ntheorist[/eluser]
Quote:CSS and JS files can easily be seen with Firefox’s Firebug extension. An htaccess protection will not help from someone jacking your files.

I’ve asked before on other web forums and there is just no way to protect client side files. Or are you speaking of someone editing your files? I have no experience in that kind of hacking.

It would be difficult to completely obfuscate your css/js files. You can use packer, minify etc to make them less readable, but those are all easily reversable

its not so much that i don't want people to be able to view the js/css files (easy with the web developer plugin for ff too), its more that i'd rather not advertise the system folder directory, which otherwise would remain in the background. Of course, a better compliment to this would be to rename the system & application directories to something less obvious - a lot of hacking is done by guessing common words/patterns.

The .htaccess though should prevent direct system folder access. And of course placing <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); at the top of all your php scripts and views, plus adding a blank index.html file helps too. The best way i know of to protect system files is to place it outside (beneath) your web root on your server. Admittedly i haven't tried this yet - thread on it here - but it seems it would make it impossible to access your system folder through the browser, making it very secure from prying eyes.

Quote:I myself dont want to use full urls everywhere because it creates http request on every load and for page with lots of images, styles, js etc. it will slow down the site.

chad is right that absolute/relative urls wont make a difference. However, you DO save http requests by combining your css and js files and i highly recommend it. I tend to have 10-12 stylesheets and multiple jquery plugins used while developing a normal sized site. That's an http request for every <link href=".."> and every javascript link. You can use a class to compress/combine them all into one file on a per-page basis, so you'd have <link href="styles/cache/45456465143621514.css"> or whatever, which is just one file with all the css in it. Same for the js, and you reduce reqests from 20+ to 2. Much more efficient. I recommend the carabiner library, as it was plug-n-play for me.

Also, i do know that FF and maybe other browsers have a habit of 'preloading' links on a webpage, even if you never ever visit them. This makes them huge memory hogs and there are tweaks you can do on your browser (type about:config in the url & google 'firefox memory tweaks'), but there's nothing you can do about the browsers of people visiting your site.

Quote:One last question, how are you guys loading the URL helper in a view?..
Views do exist in the same scope as the controller you called them in so you can use $this->load->helper('url') in a view just like you could in a controller/model. It's not good MVC practice so much, but really its just a matter of your preference and if you can keep track of where you use 'controller' code in your views. On a big site/CMS this would get messy

n
#28

[eluser]John_Betong[/eluser]
 
Somebody beat me to it.
 
 
#29

[eluser]cahva[/eluser]
[quote author="John_Betong" date="1247291023"] 
Somebody beat me to it.
 
 [/quote]
http://www.wattix.com/blog/chilligan/csi...ackson.jpg
Sorry.. just had to Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB