CodeIgniter Forums

Full Version: Loading assets (js, css, ...)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[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

El Forum

[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

El Forum

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

El Forum

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

El Forum

[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).

El Forum

[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 *

El Forum

[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" ...

El Forum

[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

El Forum

[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.

El Forum

[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)
Pages: 1 2