CodeIgniter Forums
Loading assets (js, css, ...) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Loading assets (js, css, ...) (/showthread.php?tid=12077)

Pages: 1 2


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Dauntless[/eluser]
Hi,

Problem in specific: I'm using Lightbox which is loading "image/close.gif", but since this is a relative path, it is forwarded to "myController/image/close.gif"

I've had this problem before and I solved it by creating a new view, copy pasting the CSS file in to the view and using the helper functions to create absolute paths everywhere.

Since this approach requires a lot of work (especially for the Lightbox integration), I'm sure there must be a much easier way to do this. My assets are located in folders on the root of the domain.

Thanks for your time Smile


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Seppo[/eluser]
The CSS relative paths are relative to the CSS location, so you shouldn't have that problem if the image is linked from the stylesheet.
On the other hand, if you have the relative path in the JS and you don't want to change it, you can use "base" tag


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Yash[/eluser]
use base_url() function to solve this problem.


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Dauntless[/eluser]
For the base_url() to work, all the .js files need to become .php files... Isn't there another way ?


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]EEssam[/eluser]
[quote author="Dauntless" date="1223239978"]For the base_url() to work, all the .js files need to become .php files... Isn't there another way ?[/quote]I think the solution to this issue is to create a controller to load JS and CSS files (have those files as views).


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Yash[/eluser]
[quote author="Dauntless" date="1223239978"]For the base_url() to work, all the .js files need to become .php files... Isn't there another way ?[/quote]

What are you saying. Totally incorrect.

You don't need to convert .js into .php.

Do something like this

create js folder where you have index.php .

Now

<*script type="text/javascript " src="&lt;?=base_url()?&gt;/js/file.js" *> <*/script*>

Got it mate.

remove *


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Dauntless[/eluser]
Sorry, I'm not following :# (//edit, ah, I see that it's JS that's being commented out, but my reply is still accurate)

In my view, I have this right now:
Code:
&lt; script type="text/javascript" src="&lt;?=base_url() . "js/prototype.js"; ?&gt;" &gt;&lt; /script>
But the problem is: In the (lightbox) .js, it says this:
//
Code:
LightboxOptions = Object.extend({
    fileLoadingImage:        'images/loading.gif',    
    fileBottomNavCloseImage: 'images/closelabel.gif',

And when I run it, it looks for "base_url() + myController/images/loading.gif" ...


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Yash[/eluser]
not sure will work or not try
Code:
LightboxOptions = Object.extend({
    fileLoadingImage:        './images/loading.gif',    
    fileBottomNavCloseImage: './images/closelabel.gif',

I've also face same problems.Lemme give u correct answer later


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Pascal Kriete[/eluser]
[Redacted - Reading fail]
Hint: When posting &lt;script&gt; tags use &amp;lt; and &amp;gt; instead of < and >, respectively.

[Second attempt:]
Those paths should either be absolute, or relative to your docroot:
[pre]
http://example.com/myapp/images/loading.gif
/myapp/images/loading.gif
[/pre]
@yash, your code is identical to what Dauntless posted.


Loading assets (js, css, ...) - El Forum - 10-05-2008

[eluser]Dauntless[/eluser]
The 'js' folder is in the same folder as the CI-index.php page:
/index.php
/js/lightbox.js
/js/otherLightBoxStuff.js
/images/loading.gif
/images/closelabel.gif

Aren't the paths already relative to my docroot ?

My view:
&lt; script type="text/javascript" src="&lt;?=base_url() . "js/prototype.js"; ?&gt;" &gt;&lt; /script> (added spaces)