https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • o

    orange-ram-33041

    04/22/2023, 11:24 PM
    Hmm.. good call. My real question should be why won’t that work for me- I have it already but it doesn’t seem to do anything…. Thanks @great-cartoon-12331
  • g

    great-cartoon-12331

    04/22/2023, 11:26 PM
    in general, if you have JS code i recommend putting that in a separate script file and making sure it's loaded only once e.g. have a
    <script>
    tag in your main page template
  • o

    orange-ram-33041

    04/22/2023, 11:35 PM
    That’s good to keep in mind, thank you!
  • o

    orange-ram-33041

    04/22/2023, 11:39 PM
    @great-cartoon-12331 is it ok if I only end up using that JS in a few specific places? It would still be best to render it in the main template?
  • g

    great-cartoon-12331

    04/22/2023, 11:40 PM
    should be fine as long as you hash-rev the filename and set a long cache expiry. CDNs and user browsers will store it for you efficiently
  • g

    great-cartoon-12331

    04/22/2023, 11:44 PM
    you can also use make the script a JS module which will be lazy loaded by default https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#importing_features_into_your_script
  • r

    refined-waiter-90422

    04/23/2023, 12:02 AM
    Hey there! Just wanted to let you know that using JS modules will require a server to avoid CORS restrictions, which means running them without a server may not be possible. If running without a server is important to you, then sticking with
    <script>
    might be the way to go. Hope that helps!
  • g

    great-cartoon-12331

    04/23/2023, 12:03 AM
    in this case the original question was about using htmx with a Django backend, so i assumed a server is available
  • l

    little-electrician-91324

    04/23/2023, 1:03 PM
    I have a question regarding event dispatching using the HX-Trigger-After-Swap header in htmx. If anyone, want to help, I've written up a question on stackoverflow: https://stackoverflow.com/questions/76084990/htmx-doesnt-seem-to-trigger-event-specified-by-hx-trigger-after-swap-header
  • b

    broad-doctor-65657

    04/23/2023, 8:22 PM
    Hi I have a question. Can we use pure htmx + html + api to create a website?
  • b

    broad-doctor-65657

    04/23/2023, 8:23 PM
    I prefer not to use any javascript framework while using django/django-rest-framework as the backend
  • g

    great-cartoon-12331

    04/23/2023, 8:23 PM
    i have a side project which uses only htmx and a tiny bit of client-side JS. no framework
  • b

    broad-doctor-65657

    04/23/2023, 8:24 PM
    How do you handle the permission/access to certain pages?
  • g

    great-cartoon-12331

    04/23/2023, 8:24 PM
    auth middleware in the backend with a session cookie
  • b

    broad-doctor-65657

    04/23/2023, 8:26 PM
    How about in the frontend? Sorry for the questions. I have a lot of things I want to do with my current projects and I think it would take too much time to learn other frameworks so I am looking for alternatives.
  • b

    broad-doctor-65657

    04/23/2023, 8:27 PM
    I don't know how to implement route guards using pure html, html & js
  • g

    great-cartoon-12331

    04/23/2023, 8:27 PM
    the frontend doesn't need any auth logic, the backend handles it
  • b

    broad-doctor-65657

    04/23/2023, 8:28 PM
    Thank you for answering my questions @great-cartoon-12331
  • g

    gifted-appointment-5037

    04/23/2023, 11:43 PM
    Think I'm finally happy with this approach to my webapps. Cloudflare + HTMX. Trying to get a large government project to agree to use it that I'm consulting on ATM Looking into a nice way to do Auth0 with this next https://github.com/stukennedy/cloudflare-htmx

    https://cdn.discordapp.com/attachments/725789747212976259/1099843004635811840/screenshot.png▾

  • g

    great-cartoon-12331

    04/23/2023, 11:45 PM
    wow, that's cutting-edge. and literally on the edge.
  • b

    bitter-machine-55943

    04/24/2023, 12:54 AM

    https://youtu.be/3GObi93tjZI▾

    have you seen this?
  • Hi all I m using htmx with Vite I m
    g

    great-musician-72573

    04/24/2023, 3:51 AM
    Hi all, I'm using htmx with Vite. I'm successfully importing htmx to the window object, but during dev, the Vite dev server produces modules you can include in your site layout like so:
    Copy code
    html
    <script type="module" src="/@vite/client"></script>
    <script type="module" src="/app.ts"></script>
    If you have any css imported in your code (e.g.
    import "./app.css";
    ), Vite will inject inline style tags into the head. But with
    hx-boost="true"
    and after navigating to another page, it resets the head and the Vite modules don't rerun, so the inline styles get removed. I believe there's no way to change the style tag that Vite injects (you can't add
    re-eval
    or
    hx-preserve
    ). Does anyone have any ideas on how to get Vite to rerun / htmx to keep those injected style tags? EDIT: Solved with event hook.
    • 1
    • 2
  • m

    mammoth-family-48524

    04/24/2023, 8:25 AM
    I'm not sure what's going wrong with your code. I have a project which does what you're trying to do (using HX-Trigger-After-Swap to call a returned dialog's show method). But you could try moving the JavaScript out of the HTMX snippet and onto the page it's inserted to.
  • m

    miniature-lizard-24702

    04/24/2023, 10:48 AM
    That’s cool. I want to use the edge but target golang. It all seems to use js right now
  • g

    gifted-appointment-5037

    04/24/2023, 10:56 AM
    I wanted to do the HTMX approach but without having to write a bunch of BE boilerplate code. Cloudflare is perfect because it gives you the routing structure out of the box. I just wrote some middleware to implement the _layout approach. Then all you need to do is create a folder structure with your Typescript files (in functions folder) and return `new Response(html`Hello World`)` and it just works. It'll wrap an endpoint in all _layout.ts files all the way up the hierarchy, so you use the root _layout to define you main html ... and then can use others for specific layouts for different parts of your app. So far I haven't come across a pattern I'd do in something like React or Angular that I can't do with this. And it's blazingly fast. I don't understand why the whole world isn't using the HTMX approach. It's baffling.
  • m

    miniature-lizard-24702

    04/24/2023, 10:58 AM
    It would be even better if it used go functions instead of ts/js imo
  • b

    bitter-machine-55943

    04/24/2023, 12:14 PM
    Can you do the same thing with AWS Lambda? It supports Go.
  • b

    bitter-machine-55943

    04/24/2023, 12:36 PM
    So Cloudflare Pages/Workers looks like Azure Static Web App. SWA is static content plus Azure Functions bundled together. You mention Auth0, and I recall azure has EasyAuth where you leverage their authentication, 2FA etc. and Azure has specific governmental offerings
  • m

    mysterious-toddler-20573

    04/24/2023, 3:03 PM
    https://twitter.com/htmx_org/status/1650515372867559427
  • b

    broad-doctor-65657

    04/24/2023, 3:37 PM
    I will look into it
1...110111021103...1146Latest