Search code examples
javascriptfileexternal

How to add and use an external js file in Codeigniter?


I am trying to add an external javascript file to Codeigniter application.

I have placed my external js file in the "projectname/js/" folder.

Below is the script tag src in my view page. src="http://localhost/needpcbcodeigniter/js/registration.js">

But I am getting a "Not found" error for the js file.


Solution

  • Most probably this is because the apache mod_rewrite is dealing with the js folder as a codeigniter controller name (as if you're calling http://localhost/projectname/index.php/js/registration.js)

    Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. Check it here