2

I'm trying to optimize a Symfony 1.4 project and one thing that I would like to do is to defer JavaScript loading. I'm using the use_javascript() function to include files from inside templates.

Does use_javascript() have an options parameter (...or any documentation whatsoever?)

Alternatively, is there an alternative method for adding a tag to the collection for include_javascripts()?

Thanks for any help!

2 Answers 2

4

you use use_javascript('scriptname') to specify a javascript file to load - this doesn't add the JS file to the page it just allows symfony to build a list of files to include .. then to include the files you use include_javascripts() so to be "efficient" just place the include_javascripts() at the bottom of the page ...

As suggested here (jQuery example)-> http://www.symfony-project.org/jobeet/1_4/Doctrine/en/18

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this is what I'm doing at the moment. However the way I understand it there is a difference between placing scripts at the bottom of the page and using the defer attribute. In other words, deferred load waits until the DOM is loaded before processing scripts. Scripts at bottom processes the scripts last, but still before the DOM is complete. It's possible this doesn't make a practical difference though.
@anstosa - do you have a link to this info? I'm looking for a solid source on the difference between defer and putting scripts at the bottom of the page. Thanks.
1

I am using append_to_slot('javascript') inside template. With require.js implemented Once development is finished and I want to deploy code for end users, require.js optimizer can combine the JavaScript files together and minify it for me.

I end up with single .js file included to the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.