At the moment, I have a whole bunch of html + php files with a $(document).ready function in each.
I believe that the way to go is to collate as much of my JS as possible into a single file, and that I will need to namespace the functions.
So, if I have a php file called product_edit, then I would do something like the following:
<script type="text/javascript">
$(document).ready(function(){
productActions.documentReady();
});
</script>
And then in my single site_scripts file, I could do something like this:
var productActions = {
documentReady: function() {
$('#date').change(function() {
someGlobalFunction();
productActions.getTerms();
});
$('#product_id').change(function() {
productActions.getTerms();
});
},
getTerms: function() {
//do something here
}
};
Firstly: Am I going about this in the right way? Is this overall methodology on the right track...or it is nonsense?
Secondly: it seems that my site_scripts file gets cached, so I have to clear my browser cache every single time I make any changes to it. Are there any quick ways around this?