Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Need help installing Head.JS

Hello, I need help installing Head.JS

My goal: to transform all the scripts in the header:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="/js/library/jquery.livequery.js?v=2.1.3" type="text/javascript"></script>
<script src="/js/library/jquery.form.js?v=2.1.3" type="text/javascript"></script>

in:

<script>head.js("http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js","/js/library/jquery.livequery.js?v=2.1.3","/js/library/jquery.form.js?v=2.1.3");</script>

I would like to make a regular expression to the variable Head but I need to find the hook. And also how to use it in a module.

I tested with these hooks without success:

public function Gdn_Theme_Module_After () {}
public function Gdn_Theme_Module_Handler () {}
public function Gdn_Controller_AddAsset_After () {}
public function Gdn_Controller_AddAsset_Handler () {}

Thank you for your help!

Best Answer

Answers

  • I wouldn't waste you time with this, if you were creating a new dynamic app maybe there may be a point to using it, but here I don't think it will help much and could actually cause a bunch of issues.

    However if you want some idea you might go about it you could look a the code of

    http://vanillaforums.org/addon/consolidate-plugin

    There is a bit more to it than just hooks.

    In my opinion you are better of just using a plugin like that. Obviously it is my plugin so I would say that, but resources are already controlled conditionally on the server and you can group them.

    Parallel loading happens anyway. But it is dependent on the browser itself. If a browser can only do two concurrent loads at a time that is for a reason. Soon any problems with parallel loading will be a non issue.

    Something like Consolidate balances grouping resources (based on regex pattern) with serving the separately, a balance of stability versus less requests.

    grep is your friend.

  • Thank you very much for your response !

    Head.JS is very efficient and avoids block the loading of pages.

    Currently I groups files with a fork of Minify extension.

    I will replace the class "HeadModule" in the same way that your extension and work with method: ToString()

  • I would advise against minifcation of javascript minfication/obsification of javascript is flawed except as a build process. At some point it will break. That was part of the reason behind Consolidate.

    grep is your friend.

  • ClémentClément
    edited October 2014

    Thank you very much !!!

    I removed from the HeadModule_BeforeToString_Handler() method Javascript tags and I added new files with $Head->addtag​​();

    You were right, no need to override the HeadModule class. :)

  • Again I would strongly warn you against using minify for the future.

    grep is your friend.

  • Thank you for your warning.
    I will test the module and if it is a problem, I would use Consolidate.

  • x00x00 MVP
    edited October 2014

    It is basically any new addon, you don't know if will break, even if you test you may overlook something. There worst I've seen is deleting all the discussion on a page, when selecting only one.

    In other words it break or it still runs in corrupted form.When I said it is a flawed concept I really mean it is a flawed concept.

    The only way is not flawed if the script already comes in minified form, therefore has been tested by the originator and deemed not be corrupted. But on arbitrary code expect corruption at some point.

    Also the benefit of minification nowadays is quite slight.

    grep is your friend.

Sign In or Register to comment.