brianlange Posted January 31, 2011 Share Posted January 31, 2011 I'm developing a site that uses a lot of ajax. I'm using php and the zend framework for the backend. I'm finding myself putting in a lot of javascript files in the layout file since I can't add them selectively because the head section of the page doesn't reload. Is there a way to address this issue? Thanks, Brian Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/ Share on other sites More sharing options...
sunfighter Posted February 3, 2011 Share Posted February 3, 2011 Brian please think about this. If a page is using ajax it does not reload, therefore the head does not reload. So I don't see the problem here. I'm sure you have one, but your not stating it clearly. Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/#findComment-1169257 Share on other sites More sharing options...
brianlange Posted February 3, 2011 Author Share Posted February 3, 2011 I want to add javascript files only when they are necessary. Not include them statically in the head section of my layout file. In the zend framework js files can be added dynamically in the view file but since ajax is being used this is not possible. Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/#findComment-1169285 Share on other sites More sharing options...
trq Posted February 3, 2011 Share Posted February 3, 2011 Where possible you should try and pack (and I mean pack, using jsmin or similar) all your js into 1 file anyway. It makes for less http requests. Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/#findComment-1169313 Share on other sites More sharing options...
.josh Posted February 4, 2011 Share Posted February 4, 2011 Where possible you should try and pack (and I mean pack, using jsmin or similar) all your js into 1 file anyway. It makes for less http requests. and to compact it even more (and solve your problem), you can dynamically build that .js file with server-side scripting. You'd have your .js files in a dir and have your script tag point to a single blah.js and mod_rewrite that to point to blah.php and and in blah.php you would file_get_contents the necessary ones and compact it and output the single custom file. Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/#findComment-1169681 Share on other sites More sharing options...
brianlange Posted February 4, 2011 Author Share Posted February 4, 2011 Thanks for the great advice! Quote Link to comment https://forums.phpfreaks.com/topic/226261-building-a-ajax-website/#findComment-1169946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.