Question

I have some javascript and other files in webroot/assets. I want to keep them there rather than in webroot/js for reasons I can go into if necessary but won't here for brevity.

So home.ctp links to a couple of scripts in webroot/assets/js. However, it tries to route the requests through AssetsController, which doesn't exist. I can see in the Chrome JS debugger that CakePHP is printing the HTML, layout and all, for the missing controller error page.

Additionally, I'm getting the error "Resource interpreted as script but transferred with MIME type text/html."

I have this same set-up working fine on my local machine - home.ctp finds the JS files as expected. The problem is on my remote server.

Help much appreciated!

Thanks

Was it helpful?

Solution

Specify an absolute path: http://you.com/assets/js/yours.js.

Plain markup:

<script type="text/javascript" src="http://you.com/assets/js/yours.js"></script>

Or the HTML Helper in CakePHP:

<?php echo $this->Html->script('/assets/js/yours.js'); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top