Moving header Javascript to an external file?

Hi all,

Does anyone know if it is possible to move the on-page javascript that is in the header of all skins to an external file?

The code is -

I have tried it and it appears to break the functionality of the store. Does anyone know if this possible any way? I’m trying to get the content code to be higher up the page than about line 120 but having no success.

Many thanks

Why? The code is genreated dynamically based on configurations in the admin panel. Hence making it static eliminates the configurability.

But why do you want content higher in the page? There are other ‘’ entries that use these definitions within the html code so moving it to the bottom will generated “undefined” variables (most notably select boxes and pricing ajax/jQuery routines).

Please explain the problem you’re trying to solve versus the solution you’ve come up with. Many times multiple heads are better than one.

[QUOTE]But why do you want content higher in the page?[/QUOTE]

As a company, we are currently working on a few CS-Cart sites and although we love the functionality it provides we are finding that the amount of presentation code in the skins is excessive.

As a rough example, one of our sites is being moved out of a competitor ecommerce solution into CS-Cart and the lines of code has over doubled (298 to 613). Granted, there is now more functionality but this is just to demonstrate a point.

With that in mind, we have been trying to strip down the skins. We have moved elements to external files, removed inline styles and generally reduced the amount of classes and id’s and used css more efficiently.

As I mentioned in my previous post, the largest amount of code is in the header and we have been trying to reduce it down so that pages are crawled easier by search engines. One of our SEO guys scrolled down the source code looking for the start of the body and couldn’t believe it starts at about line 120. Our old (and now redundant) solution has the body starting at about line 25. We have in the past seen big improvements in rankings just by reducing the amount of code in pages and moving content higher up the page.

Many thanks

Still a bit confused… While I can see your point for search-engines (though they usually just dump the header other than meta-data), a browser has to read the code whether it is via a link or embedded. Links are cached and embedded code is not. Given that most of the embedded code is dynamic in nature (current config settings based) I’m not sure how you could do this correctly without having the basic routines that generate it, generate it to the external file. But then the caching would see that it’s changed and load it anyway. I wouldn’t want to re-generate the files when I change an option like Locations.

Sounds like you have a good handle on what you’re trying to do for your own reasons.

I understand now why the code is needed and understand why it is better in the header than in a cached external file. I guess that we should just concentrate our efforts from the body tag onwards.

It was worth looking into as it is something I have wondered about for a long time with CS-Cart.

Many thanks