-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use static templatetag to remove hardcoded paths #30
Use static templatetag to remove hardcoded paths #30
Conversation
No. These are source handlebars templates and are not processed by Django. They are part of the gulp static build system. |
Reopening because i just reread the PR description and it seems you were aware of this but doing something I hadn't expected. Let me think about this. |
On Tue, Apr 26, 2016 at 10:40:37AM -0700, Patrick Altman wrote:
Ok, let me know if you'd like to discuss on email/IRC/whatever.
|
@tubaman It would be great to discuss this in our Pinax Slack, if you don't mind joining (http://slack.pinaxproject.com). Thank you! :) |
I'd prefer to have the discussion here for documentation purposes as we get a lot of questions about the static process so having a history of conversations related to PRs, I think is better preserved here. |
@tubaman The most immediate problem I have with I am assuming you have tested this and the |
1cff511
to
98c4cc6
Compare
On Wed, Apr 27, 2016 at 05:57:58AM -0700, Patrick Altman wrote:
I totally agree that the static static build should be separate from However, there are touch points between Django and the static assets.
Django has really nice facilities to enable us to easily manage all In this discussion I realized that part of my change didn't make it into I think this whole discussion boils down to this: Which do we care
Yup, I've tested it but running Since handlebars runs first before the Django template is processed, it Aside: If there were a "{{ ... }}" expression meant for Django, we'd Thanks for all the work. Regardless of which way this goes, Pinax is
|
Any further thoughts on this? |
@paltman ^ |
Just checking in. Any thoughts on this? |
I came across this independently while optimizing static assets on a project. I am in favor of this change, but I wonder if we could do more. The hashing / manifest during the gulp build might be better served by Django's staticfiles: https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#manifeststaticfilesstorage This will hash every file for proper caching by CDNs and browsers. This may be better served by some Node package integrated into the pipeline, but no solution has been presented for it yet. I'm open to that. I think this PR is a good first step. I will make some comments in the code to get this ready for merge. |
@@ -1 +1,2 @@ | |||
<script src='{{ assetPath "js/site.js" }}'></script> | |||
{% load staticfiles %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see this line merged with next line. Same with _styles.hbs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So like this?
{% load staticfiles %}<script src='{% static "{{ assetPath "js/site.js" }}" %}'></script>
Do you just want it to be a one-liner for some reason? I've typically seen Django template loads on separate lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The reason is that when this template is rendered by Django it won't have leading newlines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've pushed those as one-liners.
These hardcoded paths cause issues. For example, if I want to host the site at a different root path instead of '/', I have to edit these. Also, using the static template tag in the handlebars source allows me to move the site around without having to install node/npm/gulp and rebuild the assets. Also remove staticUrlRoot since we don't need it anymore. It's already defined as STATIC_URL in settings.py. DRY FTW!
98c4cc6
to
d08497c
Compare
@brosner I also like the idea of handling static assets in Python. It just seems like the tools are often weaker than those available in javascript. |
Just a note. Since we're using less, we'll always need some tool to compile that into css. I think the right thing is to have some of the pipeline in javascript(node, gulp) and some in python(django, etc). The question is: what parts of the pipeline should be in javascript and what parts are in python? |
I'm am working on something that I think will address this and borrow heavily from the ideas here though it make make it hard to just merge this as well. Either way, I appreciate your contributions @tubaman, and I've come around to your way of thinking. :) |
So in my effort to solve #45 I ended up simplifying things so there is no longer a need to have includes generated at all since per @brosner's recommendation we just let Django do the hashing. I originally avoided this idea because it used to be the case you had to add a third party library and do some configuration to get this hashing feature (the name of this popular library is slipping my memory right now). It's cool to see it added to Django and has sane defaults so that just a single line in the settings.py gets it working. The work I have done for #45 can be found in this compare: paltman/zero-gulp-removal@c277f05...master and I hope to get this backported to pinax projects before the end of the month (before our 16.10 distribution). |
Closes #45 Also, this addresses the issue many had with the static includes that were generated. Many thanks to @tubaman for bring this issue to light in #30 and while this commit makes his PR unnecessary to merge, it was his work in that PR and the follow on discussion that included @brosner pointing out that Django now includes a static storage backend that will handle the cache busting hash naming of static files for us. Closes #30
@tubaman Just pushed everything. After some testing we will create releases. For now you can test your self any pinax project by using the
|
These hardcoded paths cause issues. For example, if I want to host the
site at a different root path instead of '/', I have to edit these.
Also, using the static template tag in the handlebars source allows me
to move the site around without having to install node/npm/gulp and
rebuild the assets.
This is much better than my last attempt because I actually made the change in the handlebars source rather than the generated files.
Also, I realized that we get some DRY here by being able to remove staticUrlRoot from the handlebars config.