Welcome Guest, Not a member yet? Register   Sign In
Easier Way to Load Stylesheets?
#1

[eluser]ShoeLace1291[/eluser]
What's the easiest way to load a stylesheet that's located in the views folder without using the direct http url? I have six or seven stylesheets that need to be loaded but I can't figure out what directory to use. HTTP takes way too long to load them. I already tried the html helper link tag but that does exactly what I don't want to do.
#2

[eluser]Colin Williams[/eluser]
All flavors of HTML have one way: the <link> element. And what protocol other than HTTP would you use? Would you rather use a streaming protocol? I don't get it.

You could concatenate your stylesheets and compress them to shave the file size down and reduce the amount of requests
#3

[eluser]ShoeLace1291[/eluser]
Since my stylesheets are located in my view folders, it's a pain to type out the direct link and also doing it this way causes it to load slower. i would much rather use href='style.css' than href='http://www.site.com/style.css' because without the site url would take me right to the root directory of the site. When I use href='system/application/views/style.css', it doesn't work.
#4

[eluser]Wuushu[/eluser]
The best way is to load them with the <link> tag in your header. The alternative way is to read the file, and print it out somewhere in your HTML. The second option is much worse performance & cache wise. It's just how it is. Smile

There's various ways of optimized the loading of css-stylesheet, ETags.. "compressing".. I'd suggest searching for Yahoo's guide on it. Don't have the link handy right now. Smile
#5

[eluser]Yorick Peterse[/eluser]
[quote author="ShoeLace1291" date="1255142888"]Since my stylesheets are located in my view folders, it's a pain to type out the direct link and also doing it this way causes it to load slower. i would much rather use href='style.css' than href='http://www.site.com/style.css' because without the site url would take me right to the root directory of the site. When I use href='system/application/views/style.css', it doesn't work.[/quote]

There's no speed difference between those two since they work in the exact same way. It's the same as claiming that && is faster than AND.
#6

[eluser]Colin Williams[/eluser]
1.) Don't put your stylesheets in the views folder (you application files should be outside the root anyway)
2.) Use absolute paths like "/style.css" leaving the domain out of it
3.) Get over the "pain" of typing out 30+ char strings

Quote:When I use href=‘system/application/views/style.css’, it doesn’t work.

And I hope you realize why it doesn't. ..
#7

[eluser]skunkbad[/eluser]
[quote author="Colin Williams" date="1255144895"]
2.) Use absolute paths like "/style.css" leaving the domain out of it
[/quote]

I believe I've heard that relative links load faster than absolute, which is what you are advising, but wondering why. [strike]A request is a request, no?[/strike]

Nevermind... I just Googled it.
#8

[eluser]John_Betong[/eluser]
[quote author="Colin Williams" date="1255144895"]1.) Don't put your stylesheets in the views folder (you application files should be outside the root anyway)
2.) Use absolute paths like "/style.css" leaving the domain out of it
3.) Get over the "pain" of typing out 30+ char strings
[/quote]
 
Hi Colin,
I failed to understand why the CSS file should not be in the views folder.
 
With each new application I have adopted the programming style of having a common MY_Controller.php but renamed to MY_APPPATH.php to avoid confusion. One of the functions in my common controller is:
 
./libaries/MY_[b]APPPATH.php[/b]
Code:
function  load_partials( $data=array() )
  {
    $data['doctype'] = doctype();      
    $data['header']  = $this->load->view('_header', $data, TRUE);
    ...
    ...
    return $data;
  }
 
 
./views/_header.php // prefixed with an underscore to denote a partial view
Code:
<link
     type='text/css'
     href='<?php echo APPPATH ?>views/style_04.css'
     rel='stylesheet'
     media='all'
  />
 
 

 
./views/v_mainview.php // prefixed with v_ to denote a view page
Code:
<?php echo $doctype ?>
<head>
  <?php echo $header ?>
  <style type='text/css'>
    div {border:dotted 0px #f00}
  </style>
<head>  
<body
...
...
...
</body
</html>
 
 
edit: added view
#9

[eluser]Colin Williams[/eluser]
Well, he wanted a shorter, easier path, so I suggested a way to achieve it. Also, I keep system and application files out of publicly accessible folders. So, loading files in these folders would require some needless bending over backwards
#10

[eluser]John_Betong[/eluser]
[quote author="Colin Williams" date="1255154860"]Well, he wanted a shorter, easier path, so I suggested a way to achieve it. Also, I keep system and application files out of publicly accessible folders. So, loading files in these folders would require some needless bending over backwards[/quote]
 
Many thanks for the quick response.

I thought that it was incorrect or not good practise to have the CSS file in the views folder.
 
Maybe my latest project I will try having the system, application and also the data outside of publicly accessible folders.
 
 




Theme © iAndrew 2016 - Forum software by © MyBB