I know PG’s internal server is a mystery one serving pure html/css/js…
This has been hitting me for a long time, really frustrating… but would like to understand if it’s PG’s fault or not. In my code snippet (included at end):
both img tags gets literally the same src starting with a / (slash).
while PG shows one img correctly, It doesn’t pickup the other image
when I open the same page in vscode live server, both images are displayed correctly
Tried a lot of combinations @droidgoo, no luck… Something is fundamentally wrong… It even doubt if PG has an internal server at all, looks like it’s just opening local file for edit and renders it, may be hence we see the local file opened when we try to preview any page in the browser.
Perhaps within the app when you use just / via Javascript it takes you upwards into the internals of Pinegrow itself, someone can correct me on that. But if your image is residing directly beside your html then ./ should work in both instances correctly as long as JS is enabled as seen above. It should then correctly preview in app along with when viewed directly in a browser locally.
I’m not sure where in the Pinegrow Documentation is a good singular reference regarding things related to JS. The below holding page "docs/working-with/javascript/" would definitely be a good spot for general related javascript things for the app.
Thanks @Pinegrow_User… The ./ does work, but I’m after why / doesn’t work as it’s a valid one, especially when the / works in html and not when rendered via javascript (only in PG, other servers renders this fine).
Long story short, I have webpack on my “real” app, that outputs:
css & js minified links starting with a / (slash)
dynamic elements whose href & src also starts with a / (slash)
The first one, where I want to convert / to ./, I can use pinegrow’s below fix link, which does fix it and the css & js files successfully load.
The second one, I can’t fix it in PG as they are dynamic elements.
To summarize, / should work as it’s still valid, PG is anyway rendering it fine for inline html, while it doesn’t when generated by js (while other other servers works fine). Hence, this bug report.
Can one of the pinegrow team help here please, @Emmanuel
Yes I agree, using / does not work for me either, thats why I wondered aloud if using it via JS is going a leverl up into Pinegrow itself. Its rather odd I will agree as each are valid.
I saw your other post about JS Frameworks in the Vue thread. Hopefully staff will respond to both.
@TechAkayy
Well, / and ./ are actually interpreted differently. The first, a forward slash by itself actually refers to the root, while adding a dot before it refers to the current directory of the file it is in.
To illustrate-
With the following HTML:
With regards to the server - When you are adding the src by JS it doesn’t have the correct reference for the base file, so when it encounters the naked slash it interprets in as the root of your server without any of the intervening folders
I’m not what the right behavior should be for PG. I can see an instance where you have a nested component and in the production environment you want to access root, so I’m thinking that the “fix links” shouldn’t “repair” this. I’m wondering if having the preview interpret the naked slash differently should be the behavior. So in this example, the PG server should interpret it as:
@TechAkayy the page base href in PG is not the same as outside of PG, due to the way of how the internal web server is addressed. PG does some URL mapping behind the scenes for static HTML. That’s why the HTML example works. But it can’t do anything for dynamic JS code.
One workaround is to use relative urls like image.jpeg or ../images/image.jpeg but of course that doesn’t work if the same code is run on pages at different levels of the folder structure.
Hi @RobM, thanks very much for taking the time to explain, clearly PG using my file system as base URL for absolute paths doesn’t make sense at all.
Web servers usually have a baseURL, or at least consider the current location of the index.html file as baseURL. I have already opened my project in PG, not my whole file system. Definitely, there is opportunity for improvement here (it’s really not an improvement, I see it as a fundamental).
I have sent a follow-up on this issue via email to Pinegrow support with more details and attachments, would appreciate you having a look at it. Cheers!