The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Workflow question with JavaScript

PhilippePhilippe Member
in General edited September 2012
Hi,

I am customizing the checkout page with snippets to allow flat rate pricing for specific countries , and some other functions. 2 questions on the work flow:

-1- Is it possible to locate the code in separate .js files, rather than having the code directly in line in the checkout page (the way you can have stylesheets referred to in the checkout page) Right now, when I cache the checkout page, the system goes and reads the separate style sheets referred to in the checkout page, but ignores any .js file and caches only the inline js code

-2- (This is very newbie and you will see from the question I am an autodidact....) When I change my JS code, I have to upload the code to my server, cache it via the Foxycart admin, update the checkout page, and eventually see if it works... very, very tedious. How can I adjust the java code and see that it executes properly on the fly ? Firefox with some add on perhaps?

Cheers
Comments
  • brettbrett FoxyCart Team
    Hi @Philippe

    1: Yes, but those files need to be over https. We will be rewriting our caching so it doesn't bring external files inline, but that's not here yet. That said though, … can you explain what you mean about ignoring files? Maybe whisper me if the URLs are private?

    2: Real quick note: java != javascript :)
    That said, the best way to do it would be to link to your js on your system directly (via http if that's all you have), and allow that insecure file(s) to load. Firefox might be the easiest way to do this, as it's more forgiving by default with insecure javascript (at least, in my experience).

    So what I'd probably do would be:
    * Change the reference to the local js file you're working on to point to https://example.tld/path/to/file.js. Making it https will make our caching system skip it.
    * Cache your checkout template. The .js reference will be left alone.
    * Copy/edit your checkout template to change the https to http so it'll actually load (assuming your server doesn't actually have https capabilities).
    * Test.
    * When done, change the reference to http and recache. Then test again.

    Make sense?
  • Brett:

    -2- makes sense...

    on -1- :
    I have added some (javascript :-) ) code to my checkout to customize the country menu to limit it to AU and NZ, and am working on additional code to customize the shipping options (if you look at the checkout now , only NZ shipping works for now). This adds hundreds of lines to the page. I would rather they be in a separate file, called by:

    <script type="text/javascript" src="customshippingcode.js"> </script>

    (or even 2 separate files, with one for the standard code, and the other for the custom shipping logic):

    <script type="text/javascript" src="customshippinglogic.js">
    <script type="text/javascript" src="customshippingcode2point3.js">


    However, when I moved the code to such files, and tried to cache the checkout page, the .js filed were not pulled by the caching system (I know because i did not see them added in line in the template after caching) - not sure if is not meant to work that way; or wether it is because the checkout page is at an http address rather than an https address, or wether I should have worked and I had just had used the wrong syntax...
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    They should be being cached. Could you whisper us the store you're working with so we can take a look? It's a bit hard to debug without seeing it first hand
  • Thanks - armed with the knowledge that "they should be cached" , I researched the matter figured out the correct syntax, fixed my code and got it too work!

    Closed!
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    Just to clarify, what did you change to fix the issue?
  • Since I started over clean I am not sure what was wrong the first time :-) - In retrospect the first time , the syntax I used was somewhat not correct, but I was unable to identify whether it was indeed incorrect, or whether it was correct and your system was simply not designed to handle external .js file -

    The documentation for country/state helper, flat rate custom shipping, etc keeps referring to adding code inline, and I could not find any reference to locating the code in external files instead....perhaps it would help other to add a note to those snippets indicating that they do not have to be inline ?
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    Unless you're running a secure certificate, they're going to end up inline anyway when the template is cached - so we generally just default to inline as one of the features of FoxyCart is that you don't have to have an SSL cert for your own site.
Sign In or Register to comment.